package cn.yuanqiao.archive.detection.service.impl;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.text.SimpleDateFormat;
import java.util.*;

import cn.yuanqiao.archive.appManager.domain.*;
import cn.yuanqiao.archive.appManager.mapper.TenantCateMdataListMapper;
import cn.yuanqiao.archive.appManager.mapper.TenantCategoryMapper;
import cn.yuanqiao.archive.appManager.mapper.TenantCodeRuleMapper;
import cn.yuanqiao.archive.appManager.service.ITenantSysConfigService;
import cn.yuanqiao.archive.appManager.service.ITenantSysDictTypeService;
import cn.yuanqiao.archive.archiveFormSave.domain.YqdaArchiveForm;
import cn.yuanqiao.archive.archiveFormSave.service.IYqdaArchiveFormService;
import cn.yuanqiao.archive.danganzhengli.domain.HandOverDa;
import cn.yuanqiao.archive.danganzhengli.domain.HandOverReceive;
import cn.yuanqiao.archive.danganzhengli.domain.vo.HandOverDaVo;
import cn.yuanqiao.archive.danganzhengli.mapper.HandOverReceiveMapper;
import cn.yuanqiao.archive.danganzhengli.service.IHandOverDaService;
import cn.yuanqiao.archive.danganzhengli.service.IHandOverReceiveService;
import cn.yuanqiao.archive.detection.domain.*;
import cn.yuanqiao.archive.detection.mapper.*;
import cn.yuanqiao.archive.detection.service.IDetailLogsService;
import cn.yuanqiao.archive.detection.service.IDetectionSchemeService;
import cn.yuanqiao.archive.detection.util.DetectionUtil;
import cn.yuanqiao.archive.detection.util.EncryptionUtil;
import cn.yuanqiao.archive.detection.websocket.WebSocketServer;
import cn.yuanqiao.archive.shuzihua.service.DangAnJieShouService;
import cn.yuanqiao.archive.storeRoom.domain.Folder;
import cn.yuanqiao.archive.uploadfile.service.impl.FileService;
import cn.yuanqiao.archive.webservice.utils.XMLtoJsonUtils;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.ZipUtils;
import cn.yuanqiao.common.utils.SecurityUtils;
import com.google.common.base.Joiner;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import cn.yuanqiao.archive.detection.service.IDetectionObjectService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 四性配置内容Service业务层处理
 *
 * @author xy
 * @date 2023-08-08
 */
@Service
public class DetectionObjectServiceImpl implements IDetectionObjectService
{
    @Autowired
    private DetectionObjectMapper detectionObjectMapper;

    @Autowired
    private DetectionItemMapper detectionItemMapper;
    @Autowired
    private ITenantSysConfigService sysConfigService;

    @Autowired
    private IHandOverReceiveService handOverReceiveService;


    @Autowired
    private DetectionSchemeMapper detectionSchemeMapper;

    @Autowired
    private TenantCategoryMapper tenantCategoryMapper;

    @Autowired
    private TenantCateMdataListMapper tenantCateMdataListMapper;

    @Autowired
    private IDetectionSchemeService detectionSchemeService;

    @Autowired
    private DetailLogsMapper detailLogsMapper;

    @Autowired
    private InspectionLogsMapper inspectionLogsMapper;

    @Resource
    private DetectionUtil detectionUtil;

    @Autowired
    private IDetailLogsService detailLogsService;

    @Autowired
    private TenantCodeRuleMapper tenantCodeRuleMapper;

    @Autowired
    private InspectionRecordsMapper inspectionRecordsMapper;

    @Autowired
    private IHandOverDaService handOverDaService;

    @Autowired
    private WebSocketServer webSocketServer;

    @Autowired
    private IYqdaArchiveFormService yqdaArchiveFormService;

    @Autowired
    private ITenantSysDictTypeService sysDictTypeService;

    @Autowired
    private DangAnJieShouService dangAnJieShouService;
    @Autowired
    private HandOverReceiveMapper handOverReceiveMapper;

    @Value("${DETECTION.DID1}")
    private Long dId1;
    @Value("${DETECTION.DID2}")
    private Long dId2;
    @Value("${DETECTION.DID3}")
    private Long dId3;
    @Value("${DETECTION.DID4}")
    private Long dId4;
    @Value("${DETECTION.DID5}")
    private Long dId5;
    @Value("${DETECTION.DID6}")
    private Long dId6;
    @Value("${DETECTION.DID7}")
    private Long dId7;
    @Value("${DETECTION.DID8}")
    private Long dId8;
    @Value("${DETECTION.DID9}")
    private Long dId9;
    @Value("${DETECTION.DID10}")
    private Long dId10;
    @Value("${DETECTION.DID11}")
    private Long dId11;
    @Value("${DETECTION.DID12}")
    private Long dId12;
    @Value("${DETECTION.DID13}")
    private Long dId13;
    @Value("${DETECTION.DID14}")
    private Long dId14;
    @Value("${DETECTION.DID15}")
    private Long dId15;
    @Value("${DETECTION.DID16}")
    private Long dId16;
    @Value("${DETECTION.DID17}")
    private Long dId17;
    @Value("${DETECTION.DID18}")
    private Long dId18;
    @Value("${DETECTION.DID19}")
    private Long dId19;
    @Value("${DETECTION.DID20}")
    private Long dId20;
    @Value("${DETECTION.DID21}")
    private Long dId21;
    @Value("${DETECTION.DID22}")
    private Long dId22;
    @Value("${DETECTION.DID23}")
    private Long dId23;
    @Value("${DETECTION.DID24}")
    private Long dId24;
    @Value("${DETECTION.DID25}")
    private Long dId25;
    @Value("${DETECTION.DID26}")
    private Long dId26;
    @Value("${DETECTION.DID27}")
    private Long dId27;
    @Value("${DETECTION.DID28}")
    private Long dId28;
    @Value("${DETECTION.DID29}")
    private Long dId29;
    @Value("${DETECTION.DID30}")
    private Long dId30;
    @Value("${DETECTION.DID31}")
    private Long dId31;
    @Value("${DETECTION.DID32}")
    private Long dId32;
    @Value("${DETECTION.DID33}")
    private Long dId33;
    @Value("${DETECTION.DID34}")
    private Long dId34;
    @Value("${DETECTION.DID35}")
    private Long dId35;
    @Value("${DETECTION.DID36}")
    private Long dId36;
    @Value("${DETECTION.DID37}")
    private Long dId37;
    @Value("${DETECTION.DID38}")
    private Long dId38;
    @Value("${DETECTION.DID39}")
    private Long dId39;
    @Value("${DETECTION.DID40}")
    private Long dId40;
    @Value("${DETECTION.DID41}")
    private Long dId41;
    @Value("${DETECTION.DID42}")
    private Long dId42;
    @Value("${DETECTION.DID43}")
    private Long dId43;
    @Value("${DETECTION.DID44}")
    private Long dId44;
    @Value("${DETECTION.DID45}")
    private Long dId45;
    @Value("${DETECTION_ITEMS}")
    private String detectionItems;


    /**
     * 查询四性配置内容
     *
     * @param id 四性配置内容主键
     * @return 四性配置内容
     */
    @Override
    public DetectionObject selectDetectionObjectById(Long id)
    {
        return detectionObjectMapper.selectDetectionObjectById(id,new DetectionObject().getTableName());
    }

    /**
     * 查询四性配置内容列表
     *
     * @param detectionObject 四性配置内容
     * @return 四性配置内容
     */
    @Override
    public List<DetectionObject> selectDetectionObjectList(DetectionObject detectionObject)
    {
        return detectionObjectMapper.selectDetectionObjectList(detectionObject);
    }

    /**
     * 新增四性配置内容
     *
     * @param detectionObject 四性配置内容
     * @return 结果
     */
    @Override
    public int insertDetectionObject(DetectionObject detectionObject)
    {
        detectionObject.setCreateTime(DateUtils.getNowDate());
        return detectionObjectMapper.insertDetectionObject(detectionObject);
    }

    /**
     * 修改四性配置内容
     *
     * @param detectionObject 四性配置内容
     * @return 结果
     */
    @Override
    public int updateDetectionObject(DetectionObject detectionObject)
    {
        return detectionObjectMapper.updateDetectionObject(detectionObject);
    }

    /**
     * 批量删除四性配置内容
     *
     * @param ids 需要删除的四性配置内容主键
     * @return 结果
     */
    @Override
    public int deleteDetectionObjectByIds(Long[] ids)
    {
        return detectionObjectMapper.deleteDetectionObjectByIds(ids);
    }

    /**
     * 删除四性配置内容信息
     *
     * @param id 四性配置内容主键
     * @return 结果
     */
    @Override
    public int deleteDetectionObjectById(Long id)
    {
        return detectionObjectMapper.deleteDetectionObjectById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertDetectionObjectList(List<DetectionObject> detectionObjectList) {
        List<DetectionItem> detectionItemList=new ArrayList<>();
        List<DetectionObject> detectionObjects=new ArrayList<>();

        List<Long>objIdList=new ArrayList<>();
        int i=0;
        //将文件就行修改
        if(detectionObjectList!=null&&detectionObjectList.size()>0){
            Long pid=detectionObjectList.get(0).getpId();
            //首先将pid为这个的值删除
            if(pid!=null) {
                //判断有没有有的话修改没有新增
               // detectionObjectMapper.deleteDetectionObjectByPId(pid,new DetectionObject().getTableName());
                for(int j=0;j<detectionObjectList.size();j++){
                    //
                    DetectionObject detectionObject=detectionObjectList.get(j);
                    DetectionObject newDo=detectionObjectMapper.selectDetectionObjectById(detectionObject.getId(),new DetectionObject().getTableName());
                   if(newDo!=null) {

                       //去插入数据
                       List<DetectionItem> newList = detectionObject.getDetectionItemList();
                       if (newList != null && newList.size() > 0) {
                           objIdList.add(detectionObject.getId());
                           for (DetectionItem detectionItem : newList) {
                               detectionItem.setId(SnowflakeIdGenerator.generateId());
                               detectionItem.setObjId(detectionObject.getId());
                               detectionItem.setCreateId(SecurityUtils.getUserId());
                               detectionItem.setCreateTime(DateUtils.getNowDate());
                               detectionItemList.add(detectionItem);
                               //i += detectionItemMapper.insertDetectionItem(detectionItem);

                           }
                       }
                       detectionObjects.add(detectionObject);
                   }else{
                       //去插入数据
                       Long id= SnowflakeIdGenerator.generateId();
                       detectionObject.setId(id);
                       detectionObject.setCreateId(SecurityUtils.getUserId());
                       detectionObject.setCreateTime(DateUtils.getNowDate());
                       i+=detectionObjectMapper.insertDetectionObject(detectionObject);
                       List<DetectionItem> list=detectionObject.getDetectionItemList();
                       if(list!=null&&list.size()>0) {
                           for (DetectionItem detectionItem : list) {
                               detectionItem.setObjId(id);
                               detectionItem.setCreateId(SecurityUtils.getUserId());
                               detectionItem.setCreateTime(DateUtils.getNowDate());
                               i += detectionItemMapper.insertDetectionItem(detectionItem);
                           }
                       }
                   }
                }
                //需要把原来的数据删除 然后新增
                if(objIdList.size()>0) {
                    detectionItemMapper.deleteDetectionItemByPid(objIdList,new DetectionItem().getTableName());
                }
                //再修改
                if(detectionItemList.size()>0){
                    i += detectionItemMapper.insertBatchDetectionItem(detectionItemList,new DetectionItem().getTableName());
                }
                if(detectionObjects.size()>0){

                    i+=detectionObjectMapper.updateBatchDetectionObject(detectionObjects,new DetectionObject().getTableName());

                }
            }
        }

        return i;
    }

    @Override
    public int getDetailCount(Long pId) {
        return detectionObjectMapper.getDetailCount(pId,new DetectionObject().getTableName());
    }

    @Override
    public List<Detection> selectDetectionObjectByPid(Long pId) {
        //获取所有的列表
        DetectionObject detectionObject=new DetectionObject();
        detectionObject.setpId(pId);
        List<DetectionObject> list=detectionObjectMapper.selectDetectionObjectList(detectionObject);
        List<Detection> detections=detectionObjectMapper.getDetection(list);
        //获取list
        for(int i=0;i<list.size();i++){
            DetectionObject detection=list.get(i);
            DetectionItem detectionItem=new DetectionItem();
            detectionItem.setObjId(detection.getId());
            List<DetectionItem> detectionItems=detectionItemMapper.selectDetectionItemList(detectionItem);
            detection.setDetectionItemList(detectionItems);
            list.set(i,detection);
        }

        return createTree(0L,detections,list);
    }
    private List<Detection> createTree(Long pid, List<Detection> detections,List<DetectionObject> detectionObject) {
        List<Detection> treeList = new ArrayList<>();
        for (Detection detection : detections) {
            if (pid.equals(0)) {
                if (detection.getSuperId().equals(0)) {    //那这就是第一级节点

                    treeList.add(detection);
                    detection.setChildren(createTree(detection.getId(), detections, detectionObject));
                }
            } else {
                if (pid.equals(detection.getSuperId())) {
                    if (detection.getdType().equals("3")) {
                        for (DetectionObject detectionObject1 : detectionObject) {
                            if (detectionObject1.getdId().equals(detection.getId())) {
                                detection.setId(detectionObject1.getId());
                                detection.setIsDetection(detectionObject1.getIsDetection());
                                detection.setIsPass(detectionObject1.getIsPass());
                                detection.setDetectionItemList(detectionObject1.getDetectionItemList());
                                break;
                            }
                            //  break;
                        }
                        treeList.add(detection);
                        detection.setChildren(createTree(detection.getdId(), detections, detectionObject));
                    } else {
                        treeList.add(detection);
                        detection.setChildren(createTree(detection.getId(), detections, detectionObject));

                    }
                }
            }
//            当children为[]的时候，将他设置成null
            if (detection.getChildren() == null || detection.getChildren().size() == 0) {
                detection.setChildren(null);
            }
        }
        return treeList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map detection(List<DetectionPackage> packages) {
        String yijiaoPack = sysConfigService.selectConfigByKey("YQ_YIJIAO");
        if (StringUtils.isEmpty(yijiaoPack)) {
            throw new ServiceException("系统参数错误YQ_YIJIAO未找到配置！");
        }
        if(packages==null||packages.size()<=0){
            throw new ServiceException("未选择需要移交的档案！");

        }
        if(packages.get(0).getCode()==null||"".equals(packages.get(0).getCode())){
            throw new ServiceException("未选择需要四性检测的配置方案！");
        }
        String code=packages.get(0).getCode();

        //验证压缩包是否存在，存在就直接下载
        Long id=SnowflakeIdGenerator.generateId();
        Date date=new Date();
        File packZip = new File(yijiaoPack + id+""+date.getTime() + ".zip");
        if (!packZip.exists()) {
            //判断该文件的上级目录是否存在
            if(!packZip.getParentFile().exists()){
                packZip.getParentFile().mkdirs();
            }
            String yijiao = yijiaoPack + id+ ""+date.getTime() + File.separator;
            File file = new File(yijiao);
            if (file.exists()) {
                //删除目录重新生成
                FileUtils.deleteQuietly(file);
            }
            //通过门类ID获取档案列表
            HandOverDa handOverDa = new HandOverDa();
            handOverDa.setCategoryId(packages.get(0).getCategoryId());
            List<HandOverDaVo> list = handOverDaService.selectHandOverDa(handOverDa);
            //生成移交文件
            for (HandOverDaVo handOverDaVo : list) {
                handOverReceiveService.packXml(yijiao, handOverDaVo.getDaId(), handOverDaVo.getDaType());
            }
            //打压缩包
            ZipUtils.zip(yijiao, yijiaoPack + id+""+date.getTime());
            File file1=new File(yijiaoPack + id+""+date.getTime()+".zip");
            File file2=new File(yijiaoPack+id+".zip");
            if(!file2.exists()){
                try {
                    FileUtils.copyFile(file1, file2);
                }catch (Exception ex){
                    ex.printStackTrace();
                }
            }
            //生成后删除临时文件
            FileUtils.deleteQuietly(file);
            //打包完了解析包
        }

        //将包进行解压从而进行解析
        Map map=detectionPackage(yijiaoPack + id +""+date.getTime()+ ".zip",code,packages.get(0).getLink(),"0");
        map.put("yijiaoId",id);
        //发请求
        webSocketServer.sendToMessageById(SecurityUtils.getUserId(),"jccg");
        return map;

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map daDetection(DetectionPackage packages) {
        YqdaArchiveForm yqdaArchiveForm=new YqdaArchiveForm();
        yqdaArchiveForm.setState("0");
        yqdaArchiveForm.setUserId(String.valueOf(SecurityUtils.getUserId()));
        Long startTime=System.currentTimeMillis();
        List<YqdaArchiveForm> yqdaArchiveForms = yqdaArchiveFormService.selectYqdaArchiveFormList(yqdaArchiveForm);
        if (yqdaArchiveForms.size()==0){
            return null;
        }
        String code=packages.getCode();
        DetectionScheme detectionScheme=detectionSchemeMapper.selectDetectionSchemeByCode(code,new DetectionScheme().getTableName());
        int count=this.getDetailCount(detectionScheme.getId());
        if(count<=0){
            throw new ServiceException("该方案未配置检测项,请先配置检测项！");
        }

        Long categoryId=detectionScheme.getCategoryId();
        String subTableName=detectionScheme.getSubTableName();
        //判断该门类是项目还是组卷还是组件
        TenantCategory tenantCategory= tenantCategoryMapper.selectTenantCategoryByID(categoryId,new TenantCategory().getTableName());
        Integer type=tenantCategory.getType();
        //获取配置项
        DetectionObject detectionObject=new DetectionObject();
        detectionObject.setpId(detectionScheme.getId());
        detectionObject.setIsDetection("1");
        List<DetectionObject> detectionObjects=detectionObjectMapper.selectDetectionObjectList(detectionObject);
        Long id=SnowflakeIdGenerator.generateId();
        //去校验，验证是否成功
        Map params=new HashMap();
        params.put("dh","");
        params.put("dhList",new ArrayList<>());
        params.put("count","0");
        params.put("list",new ArrayList<>());
        params.put("parentDhList",new ArrayList<>());
        List<DetectionPackage> packages1=new ArrayList<>();
        //去判断添加
        for(int i=0;i<yqdaArchiveForms.size();i++){
            //找到全部的folderId TenantItemFolder
            YqdaArchiveForm archiveForms=yqdaArchiveForms.get(i);
            List <DetectionPackage>detectionPackages=new ArrayList<>();
            if(type.equals(3)) {
                List<Long> folderIds = detectionObjectMapper.getFolderIdsBtItemId(new TenantItemFolder().getTableName(), Long.parseLong(archiveForms.getArchiveId()),SecurityUtils.getTenantCode().toUpperCase());
                //
                params.put("list",new ArrayList<>());
                params.put("dhList",new ArrayList<>());
                for (int j=0;j<folderIds.size();j++) {
                    Long folderId=folderIds.get(j);
                    DetectionPackage d = new DetectionPackage();
                    d.setDaType(1);
                    d.setDaId(folderId);
                    d.setCategoryId(categoryId);
                    d.setCode(code);
                    d.setLink(packages.getLink());
                    //  detectionPackages.add(d);
                    params= analysisVolume(1, detectionObjects, categoryId, d, params, id, tenantCategory.getFolderTableName(),j,folderIds.size(),tenantCategory.getEfileTableName(),tenantCategory.getFileTableName());

                }
            }else{
                DetectionPackage d = new DetectionPackage();
                if(type.equals(0)) {
                    d.setDaType(0);
                }else{
                    d.setDaType(1);
                }
                d.setDaId(Long.parseLong(archiveForms.getArchiveId()));
                d.setCategoryId(categoryId);
                d.setCode(code);
                d.setLink(packages.getLink());
                detectionPackages.add(d);
            }
            packages1.addAll(detectionPackages);

        }
        for(int i=0;i<packages1.size();i++){
            //解析json然后获取内容去校验
            if(type.equals(0)) {
                params= analysisDa(type, detectionObjects, categoryId, packages1.get(i), params, id, subTableName,i,packages1.size(),tenantCategory.getEfileTableName(),"","组件","1");
            }else if(type.equals(1)){
                params= analysisVolume(type, detectionObjects, categoryId, packages1.get(i), params, id, subTableName,i,packages1.size(),tenantCategory.getEfileTableName(),tenantCategory.getFileTableName());
            }
        }
        //查询所有值插入object 以及 总记录表
        insetSxLogs(detectionObjects,id,type,params,categoryId,packages.getLink());
        Map map=new HashMap();
        map.put("sxId",id);
        return map;

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map daIdsDetection(DetectionPackage packages) {
        String code=packages.getCode();
        DetectionScheme ds=new DetectionScheme();
        TenantCategory category=new TenantCategory();

        DetectionScheme detectionScheme=detectionSchemeMapper.selectDetectionSchemeByCode(code,ds.getTableName());
        int count=this.getDetailCount(detectionScheme.getId());
        if(count<=0){
            throw new ServiceException("该方案未配置检测项,请先配置检测项！");
        }

        Long categoryId=detectionScheme.getCategoryId();
        String subTableName=detectionScheme.getSubTableName();
        //判断该门类是项目还是组卷还是组件
        TenantCategory tenantCategory= tenantCategoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());

        Integer type=packages.getDaType();
        if(packages.getMenuType().equals("1")&&packages.getDaType().equals(1)){

            subTableName=tenantCategory.getFolderTableName();
        }

        //获取配置项
        DetectionObject detectionObject=new DetectionObject();
        detectionObject.setpId(detectionScheme.getId());
        detectionObject.setIsDetection("1");

        List<DetectionObject> detectionObjects=detectionObjectMapper.selectDetectionObjectList(detectionObject);
        //去校验，验证是否成功
        String daIds=packages.getDaIds();
        List<String> daIdArr=Arrays.asList(daIds.split(","));
        List<Long> sxIds=new ArrayList<>();
        //每个一个数据
        Map params = new HashMap();
        params.put("daIdList", new ArrayList<>());
        params.put("itemIdList", new ArrayList<>());
        params.put("folderIdList", new ArrayList<>());
        params.put("allDaIdList", new ArrayList<>());
        params.put("allItemIdList", new ArrayList<>());
        params.put("allFolderIdList", new ArrayList<>());
        for(int i=0;i<daIdArr.size();i++) {
            Long id=SnowflakeIdGenerator.generateId();
            sxIds.add(id);
            params.put("dh", "");
            params.put("dhList", new ArrayList<>());
            params.put("count", "0");
            params.put("list", new ArrayList<>());
            params.put("parentDhList", new ArrayList<>());
            List<DetectionPackage> packages1 = new ArrayList<>();
            TenantItemFolder tenantItemFolder = new TenantItemFolder();
            List<DetectionPackage> detectionPackages = new ArrayList<>();
            if (type.equals(3)) {
                List<Long> folderIds = detectionObjectMapper.getFolderIdsBtItemId(tenantItemFolder.getTableName(), Long.parseLong(daIdArr.get(i)), SecurityUtils.getTenantCode());
                int count1 = 0;
                for (int j = 0; j < folderIds.size(); j++) {
                    Long folderId = folderIds.get(j);
                    DetectionPackage d = new DetectionPackage();
                    d.setDaType(1);
                    d.setDaId(folderId);
                    d.setCategoryId(categoryId);
                    d.setCode(code);
                    d.setLink(packages.getLink());
                    d.setMenuType(packages.getMenuType());
                    params = treatAnalysisVolume(1, detectionObjects, categoryId, d, params, id, tenantCategory.getFolderTableName(), j, folderIds.size(), tenantCategory.getEfileTableName(), tenantCategory.getFileTableName(), daIdArr.get(i));
                }
            } else {
                DetectionPackage d = new DetectionPackage();
                if (type.equals(0)) {
                    d.setDaType(0);
                } else {
                    d.setDaType(1);
                }
                d.setDaId(Long.parseLong(daIdArr.get(i)));
                d.setCategoryId(categoryId);
                d.setCode(code);
                d.setLink(packages.getLink());
                d.setMenuType(packages.getMenuType());
                detectionPackages.add(d);
            }
            packages1.addAll(detectionPackages);
            for (int n = 0; n < packages1.size(); n++) {
                //解析json然后获取内容去校验
                if (type.equals(0)) {
                    params = treatAnalysisDa(type, detectionObjects, categoryId, packages1.get(n), params, id, subTableName, n, packages1.size(), tenantCategory.getEfileTableName(), "", "组件", "1", 0L, "");
                } else if (type.equals(1)) {
                    params = treatAnalysisVolume(type, detectionObjects, categoryId, packages1.get(n), params, id, subTableName, n, packages1.size(), tenantCategory.getEfileTableName(), tenantCategory.getFileTableName(), "");
                }
            }
            insetSxLogs(detectionObjects,id,type,params,categoryId,packages.getLink());

        }
        List daIdList = (List) params.get("daIdList");
        List itemIdList = (List) params.get("itemIdList");
        List folderIdList = (List) params.get("folderIdList");
        List allDaIdList = (List) params.get("allDaIdList");
        List allItemIdList = (List) params.get("allItemIdList");
        List allFolderIdList = (List) params.get("allFolderIdList");
        //修改档案状态
        updateDaState(params,type,tenantCategory,sxIds);
        Map map=new HashMap();
        String menuType= packages.getMenuType();
        //  map.put("sxId",id);
        if(type.equals(3)){
            allItemIdList.removeAll(itemIdList);
            map.put("daId",itemIdList);
            if(allItemIdList.size()>0) {
                if(menuType.equals("0")) {
                    dangAnJieShouService.jieshou(categoryId, getLongList(allItemIdList));
                }else{
                    dangAnJieShouService.dgdJieshou(categoryId, getLongList(allItemIdList));
                }
            }
        }else if(type.equals(1)){
            allFolderIdList.removeAll(folderIdList);
            map.put("daId",folderIdList);
            if(allFolderIdList.size()>0) {
                if(menuType.equals("0")) {
                    dangAnJieShouService.jieshou(categoryId, getLongList(allFolderIdList));
                }else{
                    dangAnJieShouService.dgdJieshou(categoryId, getLongList(allFolderIdList));

                }
            }
        }else if (type.equals(0)){
            allDaIdList.removeAll(daIdList);
            map.put("daId",daIdList);
            if(allDaIdList.size()>0) {
                if(menuType.equals("0")) {
                    dangAnJieShouService.jieshou(categoryId, getLongList(allDaIdList));
                }else{
                    dangAnJieShouService.dgdJieshou(categoryId, getLongList(allDaIdList));
                }
            }

        }
        // map.put("sxId",id);
        return map;
    }
    @Override
    public Long getSxId(Long daId) {
        return detectionObjectMapper.getSxId(daId,SecurityUtils.getTenantCode());
    }

    public Map analysisVolume(Integer type, List<DetectionObject> detectionObjects, Long categoryId, DetectionPackage detectionPackage, Map params, Long id, String subTableName,  int p, int size,String eFileTableName,String fileTableName) {
        //首先获得所有的元数据项
        //获取档号字段
        String dh1=params.get("dh").toString();
        String dh=detectionUtil.getDh(detectionPackage.getDaId(),type,categoryId,subTableName);
        dh1+=dh+",";
        //analysis(detectionObjects,type);
        TenantCategory tenantCategory = new TenantCategory();
        String groupId = tenantCategoryMapper.selectGroupIdById(categoryId, tenantCategory.getTableName());
        String daMddata=tenantCateMdataListMapper.getMddata(groupId,categoryId,new TenantMdataList().getTableName(),1);
        //获取档案内容
        if(StringUtils.isEmpty(daMddata)){
            throw  new ServiceException("该门类卷层未设置元数据！");
        }
        //获取档案内容
        Map map=detectionObjectMapper.getFieldName(daMddata,subTableName,detectionPackage.getDaId());
        if(map==null){
            map=new HashMap();
        }

        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setIsMetadata(1);
        mdataList.setCategoryId(categoryId);
        mdataList.setType(1);
        List<TenantMdataList> tenantMdataLists = detectionSchemeService.getSchemelist(mdataList);
        for (TenantMdataList tenantMdataList : tenantMdataLists) {
            String fieldName = tenantMdataList.getFieldName().toUpperCase();
            if (tenantMdataList.getShowType() != null && "5".equals(tenantMdataList.getShowType().toString())) {
                //获取值
                String value = map.get(fieldName) == null ? "" : map.get(fieldName).toString();
                if (!StringUtils.isEmpty(value)) {
                    value = getDictVal(fieldName, value);
                    map.put(fieldName, value);
                }


            }
        }

        for (DetectionObject detectionObject : detectionObjects) {
            Long dId = detectionObject.getdId();
            String isPass=detectionObject.getIsPass();
            DetectionItem detectionItem = new DetectionItem();
            detectionItem.setObjId(detectionObject.getId());
            detectionItem.setType("1");
            List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
            for (DetectionItem item : detectionItems) {
                //获取名称然后去验证
                for (TenantMdataList tenantMdataList : tenantMdataLists) {
                    String fieldName=tenantMdataList.getFieldName().toUpperCase();
                    if(tenantMdataList.getId().toString().equals(item.getName())) {
                        if (dId.equals(dId2) && isPass.equals("0")) {
                            if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).length()> Integer.parseInt(item.getValue())) {
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据长度超出设置项", DateUtils.getNowDate(), dh, "", "1", dId);
                            }
                        } else if (dId.equals(dId3) && isPass.equals("0")) {
                            boolean flag = true;
                            if (item.getValue().equals("0")) {
                                //字符不再验证
                            } else if (item.getValue().equals("1")) {
                                //数字类型
                                flag = detectionUtil.verifyNumber(map.get(fieldName)==null?"":map.get(fieldName).toString());
                            } else if (item.getValue().equals("2")) {
                                flag = detectionUtil.checkDataType(map.get(fieldName)==null?"":map.get(fieldName).toString());
                            }
                            if (!flag) {
                                //插入错误日志
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据类型、格式检测不符合设置项", DateUtils.getNowDate(), dh, "", "1", dId);
                            }
                        } else if (dId.equals(dId4) && isPass.equals("0")) {
                            boolean flag = false;
                            String[] arr = item.getValue().split(",");
                            for (String a : arr) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                    flag = true;
                                }

                            }
                            if (!flag) {
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的值不在值域范围内", DateUtils.getNowDate(), dh, "", "1", dId);
                            }
                        } else if (dId.equals(dId5) && isPass.equals("0")) {
                            boolean flag = false;
                            String[] arr = item.getValue().split(",");
                            for (String a : arr) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                    flag = true;
                                }

                            }
                            if (!flag) {
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        } else if (dId.equals(dId6) && isPass.equals("0")) {
                            //检测项目:元数据项数据包含特殊字符检测
                            boolean flag = false;
                            String[] arr = item.getValue().split(",");
                            for (String a : arr) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) <=0) {
                                    flag = true;
                                }

                            }
                            if (!flag) {
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        } else if (dId.equals(dId7) && isPass.equals("0")) {
                            String rq =  map.get("RQ")==null?"":map.get("RQ").toString();
                           /* if (rq == null || "".equals(rq)) {
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合,日期字段未勾选元数据！", DateUtils.getNowDate(), dh, "", "1", dId);
                            }*/
                            List<String> message = detectionUtil.checkDaDh(categoryId, type, rq, tenantMdataList.getFieldName(), map, detectionPackage.getDaId(), subTableName);
                            //验证档号规则
                            for (String str : message) {
                                detailLogsService.insertNewDetailLogs(id, str, DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        } else if (dId.equals(dId8) && detectionObject.getIsPass().equals("0")) {
                            //元数据项数据重复性检测
                            //验证数据库里是否有已有这些值
                            int count = detectionUtil.checkRepeatability(subTableName, tenantMdataList.getFieldName(),map.get(fieldName)==null?"":map.get(fieldName).toString());
                            if (count > 1) {
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        }else if (dId.equals(dId19)&&detectionObject.getIsPass().equals("0")) {
                            // 元数据项完整性检测
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                detailLogsService.insertNewDetailLogs(id, "元数据项完整性检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),dh,"","1",dId);

                            }
                        }else if (dId.equals(dId20)&&detectionObject.getIsPass().equals("0")) {
                            // 元数据项完整性检测
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),dh,"","1",dId);

                            }else if(map.get(tenantMdataList.getFieldName())==null||"".equals(map.get(tenantMdataList.getFieldName()))){
                                detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段值为空！",DateUtils.getNowDate(),dh,"","1",dId);
                            }
                        }else if(dId.equals(dId26)&&detectionObject.getIsPass().equals("0")){
                            //检测项目：信息包元数据完整性检测
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                detailLogsService.insertNewDetailLogs(id, "信息包元数据完整性检测不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),dh,"","1",dId);

                            }
                        }else if(dId.equals(dId28)&&detectionObject.getIsPass().equals("0")) {
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                detailLogsService.insertNewDetailLogs(id, "信息包中元数据的可读性不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),dh,"","1",dId);


                            }
                        }else if(dId.equals(dId29)&&detectionObject.getIsPass().equals("0")) {
                            //验证是否包含
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                detailLogsService.insertNewDetailLogs(id, "目标数据库中的元数据可访问性检测不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),dh,"","1",dId);


                            }
                        }
                        break;
                    }}

            }
            if (dId.equals(dId22)&&detectionObject.getIsPass().equals("0")) {
                if(type.toString().equals("1")) {
                    // 连续性元数据项检测
                    if (!map.containsKey("AJH")) {
                        detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的案卷号为空", DateUtils.getNowDate(), dh, "", "1", dId);

                    } else {
                        if(!StringUtils.isEmpty(map.get("AJH")==null?"":map.get("AJH").toString())) {
                            List list = (List) params.get("list");

                            list.add(map.get("AJH"));
                            params.put("list", list);
                            List dhList = (List) params.get("dhList");
                            dhList.add(dh);
                            params.put("dhList", dhList);
                        }else{
                            detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的案卷号为空", DateUtils.getNowDate(), dh, "", "1", dId);
                        }
                    }
                    if (p == (size - 1)) {
                        List<DetailLogs>detailLogsList = detectionUtil.checkISContinuous((List) params.get("list"),new ArrayList(), (List)params.get("dhList"),new ArrayList<>(),id,dId,"1");
                        if (detailLogsList.size()>0) {
                            detailLogsMapper.inserDetailLogsList(detailLogsList,new DetailLogs().getTableName());


                        }
                    }
                }
            }

        }
        //查询该档案的所有卷内件
        List<DetectionPackage> packages=new ArrayList<>();
        List<Long>daIds=detectionObjectMapper.getDaIdsByFolderId(detectionPackage.getDaId(),SecurityUtils.getTenantCode().toUpperCase());
        Map map1=new HashMap();
        map1.put("dh","");
        map1.put("count","0");
        map1.put("list",new ArrayList<>());
        map1.put("dhList",new ArrayList<>());
        map1.put("parentDhList",new ArrayList<>());

        for(int i=0;i<daIds.size();i++){
            Long jianid=daIds.get(i);
            DetectionPackage dePackage=new DetectionPackage();
            dePackage.setCategoryId(categoryId);
            dePackage.setCode(detectionPackage.getCode());
            dePackage.setDaId(jianid);
            dePackage.setDaType(0);
            packages.add(dePackage);
            map1= analysisDa(2,detectionObjects,categoryId,dePackage,map1,id,fileTableName,i,daIds.size(),eFileTableName,dh,"卷内件","0");

        }


      /*  for(int c=0;c<packages.size();c++){
            DetectionPackage dPackage=packages.get(c);
        }*/
        int count=Integer.parseInt(params.get("count").toString());
        count++;
        params.put("dh",dh1);
        params.put("count",count);
        return params;
    }

    public Map analysisDa(Integer type, List<DetectionObject> detectionObjects, Long categoryId, DetectionPackage detectionPackage, Map params, Long id, String subTableName, int p, int size,String eFileTableName,String checkParentDa,String name,String checkType) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取档号字段
        String dh1=params.get("dh").toString();
        String dh=detectionUtil.getDh(detectionPackage.getDaId(),type,categoryId,subTableName);
        dh1+=dh+",";
        //analysis(detectionObjects,type);
        TenantCategory tenantCategory = new TenantCategory();
        String groupId = tenantCategoryMapper.selectGroupIdById(categoryId, tenantCategory.getTableName());
        String daMddata=tenantCateMdataListMapper.getMddata(groupId,categoryId,new TenantMdataList().getTableName(),0);
        //获取档案内容
        if(StringUtils.isEmpty(daMddata)){
            throw  new ServiceException("该门类件层未设置元数据！");
        }
        Map map=detectionObjectMapper.getFieldName(daMddata,subTableName,detectionPackage.getDaId());
        if(map==null){
            map=new HashMap();
        }
        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setIsMetadata(1);
        mdataList.setCategoryId(categoryId);
        mdataList.setType(0);
        List<TenantMdataList> tenantMdataLists = detectionSchemeService.getSchemelist(mdataList);
        for (TenantMdataList tenantMdataList : tenantMdataLists) {
            String fieldName = tenantMdataList.getFieldName().toUpperCase();
            if (tenantMdataList.getShowType() != null && "5".equals(tenantMdataList.getShowType().toString())) {
                //获取值
                String value = map.get(fieldName) == null ? "" : map.get(fieldName).toString();
                if (!StringUtils.isEmpty(value)) {
                    value = getDictVal(fieldName, value);
                    map.put(fieldName, value);
                }


            }
        }

        List<DetectionFile> detectionFileList=detectionObjectMapper.getDetectionFiles(eFileTableName,detectionPackage.getDaId());
        try {
            for (DetectionObject detectionObject : detectionObjects) {
                Long dId = detectionObject.getdId();
                String isPass = detectionObject.getIsPass();
                DetectionItem detectionItem = new DetectionItem();
                detectionItem.setObjId(detectionObject.getId());
                detectionItem.setType("0");
                List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
                for (DetectionItem item : detectionItems) {
                    //获取名称然后去验证
                    for (TenantMdataList tenantMdataList : tenantMdataLists) {
                        String fieldName = tenantMdataList.getFieldName().toUpperCase();

                        if (tenantMdataList.getId().toString().equals(item.getName())) {
                            if (dId.equals(dId2) && isPass.equals("0")) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).length() > Integer.parseInt(item.getValue())) {
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据长度超出设置项", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            }else if (dId.equals(dId3) && isPass.equals("0")) {
                                boolean flag = true;
                                if (item.getValue().equals("0")) {
                                    //字符不再验证
                                } else if (item.getValue().equals("1")) {
                                    //数字类型
                                    flag = detectionUtil.verifyNumber(map.get(fieldName)==null?"":map.get(fieldName).toString());
                                } else if (item.getValue().equals("2")) {
                                    flag = detectionUtil.checkDataType(map.get(fieldName)==null?"":map.get(fieldName).toString());
                                }
                                if (!flag) {
                                    //插入错误日志
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据类型、格式检测不符合设置项", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            } else if (dId.equals(dId4) && isPass.equals("0")) {
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "的值不在值域范围内", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            } else if (dId.equals(dId5) && isPass.equals("0")) {
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId6) && isPass.equals("0")) {
                                //检测项目:元数据项数据包含特殊字符检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) <= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId7) && isPass.equals("0")) {
                                String rq =  map.get("RQ")==null?"":map.get("RQ").toString();
                             /*   if (rq == null || "".equals(rq)) {
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合,日期字段未勾选元数据！", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }*/
                                List<String> message = detectionUtil.checkDaDh(categoryId, type, rq, tenantMdataList.getFieldName(), map, detectionPackage.getDaId(), subTableName);
                                //验证档号规则
                                for (String str : message) {
                                    detailLogsService.insertNewDetailLogs(id, str, DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId8) && detectionObject.getIsPass().equals("0")) {
                                //元数据项数据重复性检测
                                //验证数据库里是否有已有这些值
                                int count = detectionUtil.checkRepeatability(subTableName, tenantMdataList.getFieldName(),map.get(fieldName)==null?"":map.get(fieldName).toString());
                                if (count > 1) {
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId19) && detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    detailLogsService.insertNewDetailLogs(id, "元数据项完整性检测不符合要求," + name + "字段" + tenantMdataList.getFieldCaption() + "字段不存在！", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            } else if (dId.equals(dId20) && detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求," + name + "字段" + tenantMdataList.getFieldCaption() + "字段不存在！", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                } else if (map.get(tenantMdataList.getFieldName()) == null || "".equals(map.get(tenantMdataList.getFieldName()))) {
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求," + name + "字段" + tenantMdataList.getFieldCaption() + "字段值为空！", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                }
                            } else if (dId.equals(dId26) && detectionObject.getIsPass().equals("0")) {
                                //检测项目：信息包元数据完整性检测
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    detailLogsService.insertNewDetailLogs(id, "信息包元数据完整性检测不符合！" + name + "字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            } else if (dId.equals(dId28) && detectionObject.getIsPass().equals("0")) {
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    detailLogsService.insertNewDetailLogs(id, "信息包中元数据的可读性不符合！" + name + "字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);


                                }
                            } else if (dId.equals(dId29) && detectionObject.getIsPass().equals("0")) {
                                //验证是否包含
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    detailLogsService.insertNewDetailLogs(id, "目标数据库中的元数据可访问性检测不符合！" + name + "字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);


                                }
                            }
                            break;
                        }
                    }

                }
                if (dId.equals(dId30) && detectionObject.getIsPass().equals("0")) {
                    //内容数据格式检测
                    DetectionItem detectionItem1 = new DetectionItem();
                    detectionItem1.setObjId(detectionObject.getId());
                    List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                    List list = detectionUtil.verifyFormatDa(detectionItems1, detectionFileList);
                    for (Object str : list) {
                        detailLogsService.insertNewDetailLogs(id, "内容数据格式检测不包含" + str.toString(), DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                    }

                } else if (dId.equals(dId32) && detectionObject.getIsPass().equals("0")) {
                    //内容数据格式检测
                    DetectionItem detectionItem1 = new DetectionItem();
                    detectionItem1.setObjId(detectionObject.getId());
                    List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                    List list = detectionUtil.verifyFormatDa(detectionItems1, detectionFileList);
                    for (Object str : list) {
                        detailLogsService.insertNewDetailLogs(id, "内容数据格式长期可用性检测不包含" + str.toString(), DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                    }

                }else if (dId.equals(dId22) && detectionObject.getIsPass().equals("0")) {

                    // 连续性元数据项检测
                    if (!map.containsKey("JH")) {
                        detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的件号为空", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                    } else {
                        if(!StringUtils.isEmpty(map.get("JH")==null?"":map.get("JH").toString())) {
                            List list = (List) params.get("list");
                            list.add(map.get("JH"));
                            params.put("list", list);
                            List dhList = (List) params.get("dhList");
                            dhList.add(dh);
                            params.put("dhList", dhList);
                            if(!StringUtils.isEmpty(checkParentDa)){
                                List parentDhList = (List) params.get("parentDhList");
                                parentDhList.add(checkParentDa);
                                params.put("parentDhList", parentDhList);

                            }
                        }else {
                            detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的件号为空", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                        }

                    }
                    if (p == (size - 1)) {
                        List<DetailLogs>detailLogsList  = detectionUtil.checkISContinuous(new ArrayList(), (List) params.get("list"), (List) params.get("dhList"),(List) params.get("parentDhList"),id,dId,"0");
                        if (detailLogsList.size()>0) {
                            detailLogsMapper.inserDetailLogsList(detailLogsList,new DetailLogs().getTableName());

                        }
                    }
                }
            }
            //开始验证附件 获取该档案的所有附件

            for (int n = 0; n < detectionFileList.size(); n++) {
                DetectionFile detectionFile = detectionFileList.get(n);
                File file = new File(detectionFile.getDocMnt() + detectionFile.getPath());
                String jw = detectionFile.getDocFileType().toLowerCase();
                String scjs = detectionFile.getDocCreateTime();
                String realDocName = detectionFile.getRealDocName();
                String sm3=detectionFile.getSm3Hash();
                String md5=detectionFile.getMd5Hash();
                Long fileSize = Long.parseLong(detectionFile.getDocFileSize());
                for (DetectionObject detectionObject : detectionObjects) {
                    Long dId = detectionObject.getdId();
                    DetectionItem detectionItem = new DetectionItem();
                    detectionItem.setObjId(detectionObject.getId());
                    /*detectionItem.setType("0");*/
                    List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
                    for (DetectionItem item : detectionItems) {
                        boolean flag = true;
                        boolean newFlag = true;
                        boolean newFlag1 = true;
                        boolean newFlag2 = true;
                        if (dId.equals(dId1) && detectionObject.getIsPass().equals("0")) {
                            //验证固化项
                            if (item.getName().equals("1")) {
                                //计算机不校验 1sm3 5 md5
                                if(file.exists()){
                                    String val = EncryptionUtil.getSM3Hash(detectionFile.getDocMnt() + detectionFile.getPath());
                                    if(!val.equals(sm3)){
                                        detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"SM3 HASH值不一致", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                    }
                                }else {
                                    detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"文件不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }


                            } else if (item.getName().equals("5")) {
                                //计算机不校验 1sm3 5 md5
                                if(file.exists()){
                                    String val = EncryptionUtil.getMD5Hash(detectionFile.getDocMnt() + detectionFile.getPath());
                                    if(!val.equals(md5)){
                                        detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"MD5 HASH值不一致", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                    }
                                }else {
                                    detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"文件不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            }

                        }
                        else if (dId.equals(dId10) && detectionObject.getIsPass().equals("0")) {
                            if (item.getName().equals("1")) {
                                //计算机不校验
                            } else if (item.getName().equals("2")) {
                                //验证名称
                                if (file == null || !file.exists()) {
                                    flag = false;
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "名称不规范", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            } else if (item.getName().equals("3")) {
                                if (file == null || !file.exists()) {
                                    flag = false;
                                } else {
                                    if (file.length() != fileSize) {
                                        flag = false;
                                    }
                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "大小不规范", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                }
                            } else if (item.getName().equals("4")) {
                                if (file == null || !file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase().equals(jw)) {
                                    flag = false;
                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "格式不规范", DateUtils.getNowDate(), dh,checkParentDa, "0", dId);
                                }
                            } else if (item.getName().equals("5")) {
                                if (file == null || !file.exists()) {
                                    flag = false;

                                } else {
                                    // 获取文件创建时间
                                    Path path2 = Paths.get(detectionFile.getDocMnt() + detectionFile.getPath());
                                    // 获取文件属性
                                    BasicFileAttributes attributes = Files.readAttributes(path2, BasicFileAttributes.class);
                                    // 获取文件创建时间
                                    FileTime createTime = attributes.creationTime();
                                    // 将文件创建时间转换为标准格式
                                    String dateFormat = sdf.format(createTime.toMillis());

                                    if (!dateFormat.equals(scjs)) {
                                        flag = false;
                                    }

                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "上传时间不规范", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                }
                            }

                        } else if (dId.equals(dId11) && detectionObject.getIsPass().equals("0")) {
                            if (!file.exists()) {
                                newFlag = false;
                            }

                            if (!newFlag) {
                                detailLogsService.insertNewDetailLogs(id, "元数据未关联内容数据检测不符合，保存名为" + realDocName + "不存在", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                            }
                        }

                        if (dId.equals(dId27) && detectionObject.getIsPass().equals("0")) {
                            if (!file.exists()) {
                                newFlag1 = false;
                            }
                            if (n == (detectionFileList.size() - 1)) {
                                if (!newFlag1) {
                                    detailLogsService.insertNewDetailLogs(id, "信息包内容数据完整性检测不符合", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            }
                        } else if (dId.equals(dId39) && detectionObject.getIsPass().equals("0")) {
                            if (!file.exists()) {
                                newFlag2 = false;
                            }
                            if (n == (detectionFileList.size() - 1)) {
                                if (!newFlag2) {
                                    detailLogsService.insertNewDetailLogs(id, "载体中多余文件检测文件数目不一致", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            }
                        }else if(dId.equals(dId35)&&detectionObject.getIsPass().equals("0")){
                            boolean flag1=detectionUtil.IsEncryption(detectionFile.getDocMnt() + detectionFile.getPath(),file.getName().substring(file.getName().lastIndexOf(".") + 1));
                            if(flag1){
                                detailLogsService.insertNewDetailLogs(id, "信息包中包含的内容数据格式合规性检测不通过" + realDocName+"加密！", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                            }

                        }

                    }

                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
            throw new ServiceException("四性检测失败！");
        }
        int count=Integer.parseInt(params.get("count").toString());
        count++;
        params.put("dh",dh1);
        params.put("count",count);


        //开始验证
        return params;
    }
    public Map treatAnalysisVolume(Integer type, List<DetectionObject> detectionObjects, Long categoryId, DetectionPackage detectionPackage, Map params, Long id, String subTableName,  int p, int size,String eFileTableName,String fileTableName,String pId) {
        //首先获得所有的元数据项
        //获取档号字段
        List daIdList= (List) params.get("daIdList");
        List itemIdList=(List)params.get("itemIdList");
        List folderIdList=(List)params.get("folderIdList");
        List allDaIdList=(List)params.get("allDaIdList");
        List allItemIdList=(List)params.get("allItemIdList");
        List allFolderIdList=(List)params.get("allFolderIdList");
        int failCount=0;
        String dh1=params.get("dh").toString();
        String dh=detectionUtil.getDh(detectionPackage.getDaId(),type,categoryId,subTableName);
        dh1+=dh+",";
       // analysis(detectionObjects,type);
        TenantCategory tenantCategory = new TenantCategory();
        String groupId = tenantCategoryMapper.selectGroupIdById(categoryId, tenantCategory.getTableName());
        String daMddata=tenantCateMdataListMapper.getMddata(groupId,categoryId,new TenantMdataList().getTableName(),1);
        //获取档案内容
        if(StringUtils.isEmpty(daMddata)){
            throw  new ServiceException("该门类卷层未设置元数据！");
        }
        //获取档案内容
        Map map=detectionObjectMapper.getFieldName(daMddata,subTableName,detectionPackage.getDaId());
        if(map==null){
            map=new HashMap();
        }

        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setIsMetadata(1);
        mdataList.setCategoryId(categoryId);
        mdataList.setType(1);
        List<TenantMdataList> tenantMdataLists = detectionSchemeService.getSchemelist(mdataList);
        for (TenantMdataList tenantMdataList : tenantMdataLists) {
            String fieldName = tenantMdataList.getFieldName().toUpperCase();
            if (tenantMdataList.getShowType() != null && "5".equals(tenantMdataList.getShowType().toString())) {
                //获取值
                String value = map.get(fieldName) == null ? "" : map.get(fieldName).toString();
                if (!StringUtils.isEmpty(value)) {
                    value = getDictVal(fieldName, value);
                    map.put(fieldName, value);
                }


            }
        }

        for (DetectionObject detectionObject : detectionObjects) {
            Long dId = detectionObject.getdId();
            String isPass=detectionObject.getIsPass();
            DetectionItem detectionItem = new DetectionItem();
            detectionItem.setObjId(detectionObject.getId());
            detectionItem.setType("1");
            List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
            for (DetectionItem item : detectionItems) {
                //获取名称然后去验证
                for (TenantMdataList tenantMdataList : tenantMdataLists) {
                    String fieldName=tenantMdataList.getFieldName().toUpperCase();
                    if(tenantMdataList.getId().toString().equals(item.getName())) {
                        if (dId.equals(dId2) && isPass.equals("0")) {
                            if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).length()> Integer.parseInt(item.getValue())) {
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据长度超出设置项", DateUtils.getNowDate(), dh, "", "1", dId);
                            }
                        } else if (dId.equals(dId3) && isPass.equals("0")) {
                            boolean flag = true;
                            if (item.getValue().equals("0")) {
                                //字符不再验证
                            } else if (item.getValue().equals("1")) {
                                //数字类型
                                flag = detectionUtil.verifyNumber(map.get(fieldName)==null?"":map.get(fieldName).toString());
                            } else if (item.getValue().equals("2")) {
                                flag = detectionUtil.checkDataType(map.get(fieldName)==null?"":map.get(fieldName).toString());
                            }
                            if (!flag) {
                                //插入错误日志
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据类型、格式检测不符合设置项", DateUtils.getNowDate(), dh, "", "1", dId);
                            }
                        } else if (dId.equals(dId4) && isPass.equals("0")) {
                            boolean flag = false;
                            String[] arr = item.getValue().split(",");
                            for (String a : arr) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                    flag = true;
                                }

                            }
                            if (!flag) {
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的值不在值域范围内", DateUtils.getNowDate(), dh, "", "1", dId);
                            }
                        } else if (dId.equals(dId5) && isPass.equals("0")) {
                            boolean flag = false;
                            String[] arr = item.getValue().split(",");
                            for (String a : arr) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                    flag = true;
                                }

                            }
                            if (!flag) {
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        } else if (dId.equals(dId6) && isPass.equals("0")) {
                            //检测项目:元数据项数据包含特殊字符检测
                            boolean flag = false;
                            String[] arr = item.getValue().split(",");
                            for (String a : arr) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) <=0) {
                                    flag = true;
                                }

                            }
                            if (!flag) {
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        } else if (dId.equals(dId7) && isPass.equals("0")) {
                            String rq =  map.get("RQ")==null?"":map.get("RQ").toString();
                           /* if (rq == null || "".equals(rq)) {
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合,日期字段未勾选元数据！", DateUtils.getNowDate(), dh, "", "1", dId);
                            }*/
                            List<String> message = detectionUtil.checkDaDh(categoryId, type, rq, tenantMdataList.getFieldName(), map, detectionPackage.getDaId(), subTableName);
                            //验证档号规则
                            for (String str : message) {
                                failCount++;

                                detailLogsService.insertNewDetailLogs(id, str, DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        } else if (dId.equals(dId8) && detectionObject.getIsPass().equals("0")) {
                            //元数据项数据重复性检测
                            //验证数据库里是否有已有这些值
                            int count = detectionUtil.checkRepeatability(subTableName, tenantMdataList.getFieldName(),map.get(fieldName)==null?"":map.get(fieldName).toString());
                            if (count > 1) {
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), dh, "", "1", dId);
                            }

                        }else if (dId.equals(dId19)&&detectionObject.getIsPass().equals("0")) {
                            // 元数据项完整性检测
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "元数据项完整性检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),dh,"","1",dId);

                            }
                        }else if (dId.equals(dId20)&&detectionObject.getIsPass().equals("0")) {
                            // 元数据项完整性检测
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                failCount++;

                                detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),dh,"","1",dId);

                            }else if(map.get(tenantMdataList.getFieldName())==null||"".equals(map.get(tenantMdataList.getFieldName()))){
                                failCount++;

                                detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段值为空！",DateUtils.getNowDate(),dh,"","1",dId);
                            }
                        }else if(dId.equals(dId26)&&detectionObject.getIsPass().equals("0")){
                            //检测项目：信息包元数据完整性检测
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                failCount++;

                                detailLogsService.insertNewDetailLogs(id, "信息包元数据完整性检测不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),dh,"","1",dId);


                            }
                        }else if(dId.equals(dId28)&&detectionObject.getIsPass().equals("0")) {
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "信息包中元数据的可读性不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),dh,"","1",dId);
                            }
                        }else if(dId.equals(dId29)&&detectionObject.getIsPass().equals("0")) {
                            //验证是否包含
                            if(!map.containsKey(tenantMdataList.getFieldName())){
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "目标数据库中的元数据可访问性检测不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),dh,"","1",dId);


                            }
                        }
                        break;
                    }}

            }
            if (dId.equals(dId22)&&detectionObject.getIsPass().equals("0")) {
                if(type.toString().equals("1")) {
                    // 连续性元数据项检测
                    if (!map.containsKey("AJH")) {
                        failCount++;
                        detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的案卷号为空", DateUtils.getNowDate(), dh, "", "1", dId);

                    } else {
                        if(!StringUtils.isEmpty(map.get("AJH")==null?"":map.get("AJH").toString())) {
                            List list = (List) params.get("list");

                            list.add(map.get("AJH"));
                            params.put("list", list);
                            List dhList = (List) params.get("dhList");
                            dhList.add(dh);
                            params.put("dhList", dhList);
                        }else{
                            failCount++;
                            detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的案卷号为空", DateUtils.getNowDate(), dh, "", "1", dId);
                        }
                    }
                    if (p == (size - 1)) {
                        List<DetailLogs>detailLogsList = detectionUtil.checkISContinuous((List) params.get("list"),new ArrayList(), (List)params.get("dhList"),new ArrayList<>(),id,dId,"1");
                        if (detailLogsList.size()>0) {
                            failCount++;
                            detailLogsMapper.inserDetailLogsList(detailLogsList,new DetailLogs().getTableName());


                        }
                    }
                }
            }

        }
        //查询该档案的所有卷内件
        List<DetectionPackage> packages=new ArrayList<>();
        List<Long>daIds=detectionObjectMapper.getDaIdsByFolderId(detectionPackage.getDaId(),SecurityUtils.getTenantCode().toUpperCase());

        if(failCount>0){
            if(!folderIdList.contains(detectionPackage.getDaId().toString())){
                folderIdList.add(detectionPackage.getDaId().toString());
            }
            if(StringUtils.isNotEmpty(pId)) {
                if (!itemIdList.contains(pId)) {
                    itemIdList.add(pId);
                }

            }

        }
        if(!allFolderIdList.contains(detectionPackage.getDaId().toString())){
            allFolderIdList.add(detectionPackage.getDaId().toString());
        }
        if(StringUtils.isNotEmpty(pId)) {
            if (!allItemIdList.contains(pId)) {
                allItemIdList.add(pId);
            }

        }
               /*  params.put("daIdList",new ArrayList<>());
        params.put("itemIdList",new ArrayList<>());
        params.put("folderIdList",new ArrayList<>());
        params.put("allDaIdList",new ArrayList<>());
        params.put("allItemIdList",new ArrayList<>());
        params.put("allFolderIdList",new ArrayList<>());*/
        Map map1=new HashMap();
        map1.put("dh","");
        map1.put("count","0");
        map1.put("list",new ArrayList<>());
        map1.put("dhList",new ArrayList<>());
        map1.put("parentDhList",new ArrayList<>());
        map1.put("daIdList",daIdList);
        map1.put("itemIdList",itemIdList);
        map1.put("folderIdList",folderIdList);
        map1.put("allDaIdList",allDaIdList);
        map1.put("allItemIdList",allItemIdList);
        map1.put("allFolderIdList",allFolderIdList);

        for(int i=0;i<daIds.size();i++){
            Long jianid=daIds.get(i);
            DetectionPackage dePackage=new DetectionPackage();
            dePackage.setCategoryId(categoryId);
            dePackage.setCode(detectionPackage.getCode());
            dePackage.setDaId(jianid);
            dePackage.setDaType(0);
            dePackage.setMenuType(detectionPackage.getMenuType());
            packages.add(dePackage);
            map1= treatAnalysisDa(2,detectionObjects,categoryId,dePackage,map1,id,fileTableName,i,daIds.size(),eFileTableName,dh,"卷内件","0",detectionPackage.getDaId(),pId);

        }


      /*  for(int c=0;c<packages.size();c++){
            DetectionPackage dPackage=packages.get(c);
        }*/
        int count=Integer.parseInt(params.get("count").toString());
        count++;
       /* map1.put("daIdList",daIdList);
        map1.put("itemIdList",itemIdList);
        map1.put("folderIdList",folderIdList);
        map1.put("allDaIdList",allDaIdList);
        map1.put("allItemIdList",allItemIdList);
        map1.put("allFolderIdList",allFolderIdList);*/
        params.put("dh",dh1);
        params.put("count",count);
        params.put("daIdList",daIdList);
        params.put("itemIdList",itemIdList);
        params.put("folderIdList",folderIdList);
        params.put("allDaIdList",allDaIdList);
        params.put("allItemIdList",allItemIdList);
        params.put("allFolderIdList",allFolderIdList);
        return params;
    }
    public Map treatAnalysisDa(Integer type, List<DetectionObject> detectionObjects, Long categoryId, DetectionPackage detectionPackage, Map params, Long id, String subTableName, int p, int size,String eFileTableName,String checkParentDa,String name,String checkType,Long folderId,String pId) {
        List daIdList= (List) params.get("daIdList");
        List itemIdList=(List)params.get("itemIdList");
        List folderIdList=(List)params.get("folderIdList");
        List allDaIdList=(List)params.get("allDaIdList");
        List allItemIdList=(List)params.get("allItemIdList");
        List allFolderIdList=(List)params.get("allFolderIdList");
        int failCount=0;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取档号字段
        String dh1=params.get("dh").toString();
        String dh=detectionUtil.getDh(detectionPackage.getDaId(),type,categoryId,subTableName);
        dh1+=dh+",";
       // analysis(detectionObjects,type);
        TenantCategory tenantCategory = new TenantCategory();
        String groupId = tenantCategoryMapper.selectGroupIdById(categoryId, tenantCategory.getTableName());
        String daMddata=tenantCateMdataListMapper.getMddata(groupId,categoryId,new TenantMdataList().getTableName(),0);
        //获取档案内容
        if(StringUtils.isEmpty(daMddata)){
            throw  new ServiceException("该门类件层未设置元数据！");
        }
        Map map=detectionObjectMapper.getFieldName(daMddata,subTableName,detectionPackage.getDaId());
        if(map==null){
            map=new HashMap();
        }
        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setIsMetadata(1);
        mdataList.setCategoryId(categoryId);
        mdataList.setType(0);
        List<TenantMdataList> tenantMdataLists = detectionSchemeService.getSchemelist(mdataList);
        for (TenantMdataList tenantMdataList : tenantMdataLists) {
            String fieldName = tenantMdataList.getFieldName().toUpperCase();
            if (tenantMdataList.getShowType() != null && "5".equals(tenantMdataList.getShowType().toString())) {
                //获取值
                String value = map.get(fieldName) == null ? "" : map.get(fieldName).toString();
                if (!StringUtils.isEmpty(value)) {
                    value = getDictVal(fieldName, value);
                    map.put(fieldName, value);
                }


            }
        }

        List<DetectionFile> detectionFileList=detectionObjectMapper.getDetectionFiles(eFileTableName,detectionPackage.getDaId());
        try {
            for (DetectionObject detectionObject : detectionObjects) {
                Long dId = detectionObject.getdId();
                String isPass = detectionObject.getIsPass();
                DetectionItem detectionItem = new DetectionItem();
                detectionItem.setObjId(detectionObject.getId());
                detectionItem.setType("0");
                List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
                for (DetectionItem item : detectionItems) {
                    //获取名称然后去验证
                    for (TenantMdataList tenantMdataList : tenantMdataLists) {
                        String fieldName = tenantMdataList.getFieldName().toUpperCase();

                        if (tenantMdataList.getId().toString().equals(item.getName())) {
                            if (dId.equals(dId2) && isPass.equals("0")) {
                                if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).length() > Integer.parseInt(item.getValue())) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据长度超出设置项", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            }else if (dId.equals(dId3) && isPass.equals("0")) {
                                boolean flag = true;
                                if (item.getValue().equals("0")) {
                                    //字符不再验证
                                } else if (item.getValue().equals("1")) {
                                    //数字类型
                                    flag = detectionUtil.verifyNumber(map.get(fieldName)==null?"":map.get(fieldName).toString());
                                } else if (item.getValue().equals("2")) {
                                    flag = detectionUtil.checkDataType(map.get(fieldName)==null?"":map.get(fieldName).toString());
                                }
                                if (!flag) {
                                    //插入错误日志
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据类型、格式检测不符合设置项", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            } else if (dId.equals(dId4) && isPass.equals("0")) {
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "的值不在值域范围内", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            } else if (dId.equals(dId5) && isPass.equals("0")) {
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) >= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId6) && isPass.equals("0")) {
                                //检测项目:元数据项数据包含特殊字符检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if ((map.get(fieldName)==null?"":map.get(fieldName).toString()).indexOf(a) <= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "元数据项数据值不合理", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId7) && isPass.equals("0")) {
                                String rq =  map.get("RQ")==null?"":map.get("RQ").toString();
                             /*   if (rq == null || "".equals(rq)) {
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合,日期字段未勾选元数据！", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }*/
                                List<String> message = detectionUtil.checkDaDh(categoryId, type, rq, tenantMdataList.getFieldName(), map, detectionPackage.getDaId(), subTableName);
                                //验证档号规则
                                for (String str : message) {
                                    failCount++;

                                    detailLogsService.insertNewDetailLogs(id, str, DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId8) && detectionObject.getIsPass().equals("0")) {
                                //元数据项数据重复性检测
                                //验证数据库里是否有已有这些值
                                int count = detectionUtil.checkRepeatability(subTableName, tenantMdataList.getFieldName(),map.get(fieldName)==null?"":map.get(fieldName).toString());
                                if (count > 1) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, name + "字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }

                            } else if (dId.equals(dId19) && detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "元数据项完整性检测不符合要求," + name + "字段" + tenantMdataList.getFieldCaption() + "字段不存在！", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            } else if (dId.equals(dId20) && detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求," + name + "字段" + tenantMdataList.getFieldCaption() + "字段不存在！", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                } else if (map.get(tenantMdataList.getFieldName()) == null || "".equals(map.get(tenantMdataList.getFieldName()))) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求," + name + "字段" + tenantMdataList.getFieldCaption() + "字段值为空！", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                }
                            } else if (dId.equals(dId26) && detectionObject.getIsPass().equals("0")) {
                                //检测项目：信息包元数据完整性检测
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "信息包元数据完整性检测不符合！" + name + "字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            } else if (dId.equals(dId28) && detectionObject.getIsPass().equals("0")) {
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "信息包中元数据的可读性不符合！" + name + "字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);


                                }
                            } else if (dId.equals(dId29) && detectionObject.getIsPass().equals("0")) {
                                //验证是否包含
                                if (!map.containsKey(tenantMdataList.getFieldName())) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "目标数据库中的元数据可访问性检测不符合！" + name + "字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);


                                }
                            }
                            break;
                        }
                    }

                }
                if (dId.equals(dId30) && detectionObject.getIsPass().equals("0")) {
                    //内容数据格式检测
                    DetectionItem detectionItem1 = new DetectionItem();
                    detectionItem1.setObjId(detectionObject.getId());
                    List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                    List list = detectionUtil.verifyFormatDa(detectionItems1, detectionFileList);
                    for (Object str : list) {
                        failCount++;
                        detailLogsService.insertNewDetailLogs(id, "内容数据格式检测不包含" + str.toString(), DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                    }

                } else if (dId.equals(dId32) && detectionObject.getIsPass().equals("0")) {
                    //内容数据格式检测
                    DetectionItem detectionItem1 = new DetectionItem();
                    detectionItem1.setObjId(detectionObject.getId());
                    List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                    List list = detectionUtil.verifyFormatDa(detectionItems1, detectionFileList);
                    for (Object str : list) {
                        failCount++;
                        detailLogsService.insertNewDetailLogs(id, "内容数据格式长期可用性检测不包含" + str.toString(), DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                    }

                }else if (dId.equals(dId22) && detectionObject.getIsPass().equals("0")) {

                    // 连续性元数据项检测
                    if (!map.containsKey("JH")) {
                        failCount++;
                        detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的件号为空", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                    } else {
                        if(!StringUtils.isEmpty(map.get("JH")==null?"":map.get("JH").toString())) {
                            List list = (List) params.get("list");
                            list.add(map.get("JH"));
                            params.put("list", list);
                            List dhList = (List) params.get("dhList");
                            dhList.add(dh);
                            params.put("dhList", dhList);
                            if(!StringUtils.isEmpty(checkParentDa)){
                                List parentDhList = (List) params.get("parentDhList");
                                parentDhList.add(checkParentDa);
                                params.put("parentDhList", parentDhList);

                            }
                        }else {
                            failCount++;
                            detailLogsService.insertNewDetailLogs(id, "档案ID为" + detectionPackage.getDaId() + "的件号为空", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                        }

                    }
                    if (p == (size - 1)) {
                        List<DetailLogs>detailLogsList  = detectionUtil.checkISContinuous(new ArrayList(), (List) params.get("list"), (List) params.get("dhList"),(List) params.get("parentDhList"),id,dId,"0");
                        if (detailLogsList.size()>0) {
                            failCount++;
                            detailLogsMapper.inserDetailLogsList(detailLogsList,new DetailLogs().getTableName());

                        }
                    }
                }
            }
            //开始验证附件 获取该档案的所有附件

            for (int n = 0; n < detectionFileList.size(); n++) {
                DetectionFile detectionFile = detectionFileList.get(n);
                File file = new File(detectionFile.getDocMnt() + detectionFile.getPath());
                String jw = detectionFile.getDocFileType().toLowerCase();
                String scjs = detectionFile.getDocCreateTime();
                String realDocName = detectionFile.getRealDocName();
                String sm3=detectionFile.getSm3Hash();
                String md5=detectionFile.getMd5Hash();
                Long fileSize = Long.parseLong(detectionFile.getDocFileSize());
                for (DetectionObject detectionObject : detectionObjects) {
                    Long dId = detectionObject.getdId();
                    DetectionItem detectionItem = new DetectionItem();
                    detectionItem.setObjId(detectionObject.getId());
                    /*detectionItem.setType("0");*/
                    List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
                    for (DetectionItem item : detectionItems) {
                        boolean flag = true;
                        boolean newFlag = true;
                        boolean newFlag1 = true;
                        boolean newFlag2 = true;

                        if (dId.equals(dId1) && detectionObject.getIsPass().equals("0")) {
                            //验证固化项
                            if (item.getName().equals("1")) {
                                //计算机不校验 1sm3 5 md5
                                if(file.exists()){
                                    String val = EncryptionUtil.getSM3Hash(detectionFile.getDocMnt() + detectionFile.getPath());
                                    if(!val.equals(sm3)){
                                        detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"SM3 HASH值不一致", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                    }
                                }else {
                                    detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"文件不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }


                            } else if (item.getName().equals("5")) {
                                //计算机不校验 1sm3 5 md5
                                if(file.exists()){
                                    String val = EncryptionUtil.getMD5Hash(detectionFile.getDocMnt() + detectionFile.getPath());
                                    if(!val.equals(md5)){
                                        detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"MD5 HASH值不一致", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                    }
                                }else {
                                    detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+realDocName+"文件不存在", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            }

                        }

                        if (dId.equals(dId10) && detectionObject.getIsPass().equals("0")) {
                            if (item.getName().equals("1")) {
                                //计算机不校验
                            } else if (item.getName().equals("2")) {
                                //验证名称
                                if (file == null || !file.exists()) {
                                    flag = false;
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "名称不规范", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);

                                }
                            } else if (item.getName().equals("3")) {
                                if (file == null || !file.exists()) {
                                    flag = false;
                                } else {
                                    if (file.length()!=fileSize) {
                                        flag = false;
                                    }
                                }
                                if (!flag) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "大小不规范", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                }
                            } else if (item.getName().equals("4")) {
                                if (file == null || !file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase().equals(jw)) {
                                    flag = false;
                                }
                                if (!flag) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "格式不规范", DateUtils.getNowDate(), dh,checkParentDa, "0", dId);
                                }
                            } else if (item.getName().equals("5")) {
                                if (file == null || !file.exists()) {
                                    flag = false;

                                } else {
                                    // 获取文件创建时间
                                    Path path2 = Paths.get(detectionFile.getDocMnt() + detectionFile.getPath());
                                    // 获取文件属性
                                    BasicFileAttributes attributes = Files.readAttributes(path2, BasicFileAttributes.class);
                                    // 获取文件创建时间
                                    FileTime createTime = attributes.creationTime();
                                    // 将文件创建时间转换为标准格式
                                    String dateFormat = sdf.format(createTime.toMillis());

                                    if (!dateFormat.equals(scjs)) {
                                        flag = false;
                                    }

                                }
                                if (!flag) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致," + realDocName + "上传时间不规范", DateUtils.getNowDate(), dh, checkParentDa, "0", dId);
                                }
                            }
                        } else if (dId.equals(dId11) && detectionObject.getIsPass().equals("0")) {
                            if (!file.exists()) {
                                newFlag = false;
                            }

                            if (!newFlag) {
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "元数据未关联内容数据检测不符合，保存名为" + realDocName + "不存在", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                            }
                        }
                        if (dId.equals(dId27) && detectionObject.getIsPass().equals("0")) {
                            if (!file.exists()) {
                                newFlag1 = false;
                            }
                            if (n == (detectionFileList.size() - 1)) {
                                if (!newFlag1) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "信息包内容数据完整性检测不符合", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);

                                }
                            }
                        } else if (dId.equals(dId39) && detectionObject.getIsPass().equals("0")) {
                            if (!file.exists()) {
                                newFlag2 = false;
                            }
                            if (n == (detectionFileList.size() - 1)) {
                                if (!newFlag2) {
                                    failCount++;
                                    detailLogsService.insertNewDetailLogs(id, "载体中多余文件检测文件数目不一致", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);
                                }
                            }
                        }else if(dId.equals(dId35)&&detectionObject.getIsPass().equals("0")){
                            boolean flag1=detectionUtil.IsEncryption(detectionFile.getDocMnt() + detectionFile.getPath(),file.getName().substring(file.getName().lastIndexOf(".") + 1));
                            if(flag1){
                                failCount++;
                                detailLogsService.insertNewDetailLogs(id, "信息包中包含的内容数据格式合规性检测不通过" + realDocName+"加密！", DateUtils.getNowDate(), dh, checkParentDa, checkType, dId);

                            }


                        }

                    }

                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
            throw new ServiceException("四性检测失败！");
        }
        int count=Integer.parseInt(params.get("count").toString());
        count++;
        params.put("dh",dh1);
        params.put("count",count);


        if(failCount>0){
            if(!daIdList.contains(detectionPackage.getDaId().toString())){
                daIdList.add(detectionPackage.getDaId().toString());
            }
            if(folderId!=0L){
                if(!folderIdList.contains(folderId.toString())){
                    folderIdList.add(folderId.toString());
                }
            }
            if(StringUtils.isNotEmpty(pId)){
                if(!itemIdList.contains(pId)){
                    itemIdList.add(pId);
                }
            }
        }

        if(!allDaIdList.contains(detectionPackage.getDaId().toString())){
            allDaIdList.add(detectionPackage.getDaId().toString());
        }
        if(folderId!=0L){
            if(!allFolderIdList.contains(folderId.toString())){
                allFolderIdList.add(folderId.toString());
            }
        }
        if(StringUtils.isNotEmpty(pId)){
            if(!allItemIdList.contains(pId)){
                allItemIdList.add(pId);
            }
        }

        params.put("daIdList",daIdList);
        params.put("itemIdList",itemIdList);
        params.put("folderIdList",folderIdList);
        params.put("allDaIdList",allDaIdList);
        params.put("allItemIdList",allItemIdList);
        params.put("allFolderIdList",allFolderIdList);

        //开始验证
        return params;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map detectionPackage(String path, String code,String link,String lx) {
        String encode = sysConfigService.selectConfigByKey("DECOMPRESSION_ENCODING");
        if (StringUtils.isEmpty(encode)) {
            throw new ServiceException("系统参数错误DECOMPRESSION_ENCODING未找到配置！");
        }
        File file = new File(path);
        String newPath = file.getParent() + File.separator + "detection" + File.separator+(file.getName().substring(0,file.getName().lastIndexOf(".")));
        //  ZipUtils.unZip(file, newPath, encode);
        FileService.decompress(file.getAbsolutePath(),newPath,encode);  //解压文件
        //对文件进行解析
        //通过code获取方案
        DetectionScheme detectionScheme = detectionSchemeMapper.selectDetectionSchemeByCode(code, new DetectionScheme().getTableName());
        int count = this.getDetailCount(detectionScheme.getId());
        if (count <= 0) {
            throw new ServiceException("该方案未配置检测项,请先配置检测项！");
        }


        Long categoryId = detectionScheme.getCategoryId();
        //通过categoryId获取到值

        String subTableName = detectionScheme.getSubTableName();
        //判断该门类是项目还是组卷还是组件
        TenantCategory tenantCategory = tenantCategoryMapper.selectTenantCategoryByID(categoryId, new TenantCategory().getTableName());
        Integer type = tenantCategory.getType();
        //获取配置项
        DetectionObject detectionObject = new DetectionObject();
        detectionObject.setpId(detectionScheme.getId());
        detectionObject.setIsDetection("1");
        List<DetectionObject> detectionObjects = detectionObjectMapper.selectDetectionObjectList(detectionObject);
        //获取文件夹下所有叫档案元数据.xml的文件进行四性检测
        List<String> list = getFiles(newPath , new ArrayList());
        Long id = SnowflakeIdGenerator.generateId();
        //去校验，验证是否成功
        Map params = new HashMap();
        params.put("dh", "");
        params.put("dhList", new ArrayList<>());

        params.put("count", "0");
        params.put("list", new ArrayList<>());
        params.put("parentDhList", new ArrayList<>());

        Long startTime = new Date().getTime();
        for (int i = 0; i < list.size(); i++) {
            //解析json然后获取内容去校验
            if (type.equals(0)) {
                params = analysisXml(type, detectionObjects, categoryId, list.get(i), params, id, subTableName, i, list.size(),lx);
            } else if (type.equals(1) || type.equals(3)) {
                params = analysisVolumeXml(type, detectionObjects, categoryId, list.get(i), params, id, tenantCategory.getFolderTableName(), tenantCategory.getFileTableName(), i, list.size(),lx);
            }

        }
        //查询所有值插入object 以及 总记录表
        Map<String,Object> map1=insetSxLogs(detectionObjects,id,type,params,categoryId,link);
        String dId="";
        int znum=0;
        int failNum=0;
        if(map1.containsKey("dId")){
            dId=map1.get("dId").toString();
        }
        if(map1.containsKey("znum")){
            znum=Integer.parseInt(map1.get("znum").toString());
        }
        if(map1.containsKey("failNum")){
            failNum=Integer.parseInt(map1.get("failNum").toString());
        }
        Long endTime = new Date().getTime();
        //删除解析包
        FileUtils.deleteQuietly(new File(newPath + file.getName().substring(0, file.getName().lastIndexOf("."))));
        //获取数据库里的检测
        if (dId.length() > 1) {
            dId = dId.substring(1);
        }
        String jcfw = "";
        String jcfwId="";
        if (!StringUtils.isEmpty(dId)) {
            jcfw = inspectionLogsMapper.getJcfw(dId, id, new InspectionLogs().getTableName());
            //获取检测项的id，通过id判断检测了哪项
            jcfwId=inspectionLogsMapper.getJcfwId(dId, id, new InspectionLogs().getTableName());
        }
        Map map = new HashMap();
        map.put("jcsj", endTime - startTime);
        map.put("jczs", list.size());
        map.put("jcpj", znum + "," + failNum);
        map.put("jcfw", jcfw);
        map.put("sxId", id);
        map.put("failNum", failNum);
        String [] items=detectionItems.split(";");
        for(int j=0;j<items.length;j++){
            Long item=Long.parseLong(items[j]);
            if(j==0){
                //真实性检测
                if(jcfwId.indexOf(item.toString())>-1){
                    int count1=detectionObjectMapper.getFailCount(item,new InspectionLogs().getTableName(),id);
                    map.put("zsx",count1);
                }
            }else if(j==1){
                //完整性检测
                if(jcfwId.indexOf(item.toString())>-1){
                    int count1=detectionObjectMapper.getFailCount(item,new InspectionLogs().getTableName(),id);
                    map.put("wzx",count1);

                }
            }else if(j==2){
                //可用性检测
                if(jcfwId.indexOf(item.toString())>-1){
                    int count1=detectionObjectMapper.getFailCount(item,new InspectionLogs().getTableName(),id);
                    map.put("kyx",count1);

                }
            }else if(j==3){
                //安全性检测
                if(jcfwId.indexOf(item.toString())>-1){
                    int count1=detectionObjectMapper.getFailCount(item,new InspectionLogs().getTableName(),id);
                    map.put("aqx",count1);

                }
            }
        }

        return map;
    }

    public Map analysisVolumeXml(Integer type, List<DetectionObject> detectionObjects, Long categoryId, String path, Map params, Long id, String subTableName,String fileTableName,int p,int num,String lx) {
      //  analysis(detectionObjects,type);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String dh=params.get("dh").toString();
        int count1=Integer.parseInt(params.get("count").toString());
        try {
            InputStreamReader o = new InputStreamReader(new FileInputStream(path));
            String xml = org.apache.commons.io.IOUtils.toString(o);
            net.sf.json.xml.XMLSerializer xmlSerializer = new net.sf.json.xml.XMLSerializer();
            net.sf.json.JSONObject json = (net.sf.json.JSONObject) xmlSerializer.read(xml);
            o.close();
            com.alibaba.fastjson2.JSONObject archiveData = XMLtoJsonUtils.startXMLToJSON(new File(path));
            String archiveType = archiveData.getJSONObject("被签名对象").getJSONObject("封装内容").getJSONObject("档案实体块").getString("聚合层次");
            Integer type1 = null;
            Boolean xmBl =  archiveData.getJSONObject("被签名对象").getJSONObject("封装内容").getJSONObject("档案实体块").getJSONObject("内容描述").containsKey("项目层");
            if(xmBl){
                type1 = 3;
            }else if("组卷".equals(archiveType)){
                type1 = 1;
            }else if("文件".equals(archiveType)){
                type1 = 0;
            }
            if(type1!=type){

                throw new ServiceException("门类类型不匹配！！！");
            }

            TenantMdataList mdataList = new TenantMdataList();
            mdataList.setIsMetadata(1);
            mdataList.setCategoryId(categoryId);
            mdataList.setType(1);
            List<TenantMdataList> tenantMdataLists = detectionSchemeService.getSchemelist(mdataList);
            //获取该项的档号字段
            String pathName="";
            String fileSizeName="";
            String hzName="";
            String mntPathName="";
            String scjsName="";
            String realDocName="";
            String md5Hash="";
            String sm3Hash="";
            String juanrq = "";
            String jianrq= "";
            String dhzd="";
            String jianJh="";
            String juanAjh="";
            TenantCategory tenantCategory=tenantCategoryMapper.selectTenantCategoryByID(categoryId,new TenantCategory().getTableName());
            List<Map<String,Object>> maps=detectionObjectMapper.getName(tenantCategory.getGroupId(),2," FIELD_NAME='PATH' OR FIELD_NAME='DOC_FILE_SIZE' OR FIELD_NAME='DOC_FILE_TYPE' OR FIELD_NAME='DOC_MNT' OR FIELD_NAME='ACTION_TIME' OR  FIELD_NAME='REAL_DOC_NAME' OR  FIELD_NAME='FILE_ONLY_VAL_GM' OR  FIELD_NAME='FILE_ONLY_VAL' ",new TenantMdataList().getTableName());
            List<Map<String,Object>> jianMaps=detectionObjectMapper.getName(tenantCategory.getGroupId(),0," FIELD_NAME='RQ' OR FIELD_NAME='DH'  OR FIELD_NAME='JH' ",new TenantMdataList().getTableName());
            List<Map<String,Object>> juanMaps=detectionObjectMapper.getName(tenantCategory.getGroupId(),1," FIELD_NAME='RQ' OR FIELD_NAME='DH' OR FIELD_NAME='AJH'  ",new TenantMdataList().getTableName());

            for(Map map:maps){
                if(map.get("FIELD_NAME").equals("PATH")){
                    pathName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("DOC_FILE_SIZE")){
                    fileSizeName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("DOC_FILE_TYPE")){
                    hzName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("DOC_MNT")){
                    mntPathName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("ACTION_TIME")){
                    scjsName=map.get("FIELD_CAPTION").toString();

                }else if(map.get("FIELD_NAME").equals("REAL_DOC_NAME")){
                    realDocName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("FILE_ONLY_VAL")){
                    md5Hash=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("FILE_ONLY_VAL_GM")){
                    sm3Hash=map.get("FIELD_CAPTION").toString();
                }
            }
            for(Map map:jianMaps){
                if(map.get("FIELD_NAME").equals("RQ")){
                    jianrq=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("DH")){
                    dhzd=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("JH")){
                    jianJh=map.get("FIELD_CAPTION").toString();
                }
            }
            for(Map map:juanMaps){
                if(map.get("FIELD_NAME").equals("RQ")){
                    juanrq=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("AJH")){
                    juanAjh=map.get("FIELD_CAPTION").toString();
                }

            }
            //各项检测先解析xml
            //
            net.sf.json.JSONObject j=null;
            net.sf.json.JSONObject j1 = json.getJSONObject("被签名对象");
            Object j2=j1.get("封装内容");

            //判断封装内容是JSONOBJECT还是JSONARRY
            if(j2 instanceof JSONArray){
                j=((net.sf.json.JSONArray) j2).getJSONObject(0);
                //.getJSONObject("档案实体块");
            }else if(j2 instanceof JSONObject){
                j=((JSONObject) j2).getJSONObject("档案实体块");
            }
            dh += j.getString("电子档案号")+",";
            //获取内容描述
            net.sf.json.JSONObject n = j.getJSONObject("内容描述");
            //开始验证各项
            Object jian=n.get("件层集");

            count1++;
            for (DetectionObject detectionObject : detectionObjects) {
                Long dId = detectionObject.getdId();
                DetectionItem detectionItem = new DetectionItem();
                detectionItem.setObjId(detectionObject.getId());
                detectionItem.setType("1");
                List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
                if (dId.equals(dId1)&&detectionObject.getIsPass().equals("0")) {
                    //固化信息有效性检测
                }
                for (DetectionItem item : detectionItems) {
                    //获取名称然后去验证
                    for (TenantMdataList tenantMdataList : tenantMdataLists) {
                        if (tenantMdataList.getId().toString().equals(item.getName())) {
                            String value="";
                            if(n.has(tenantMdataList.getFieldCaption())){
                                value = n.getString(tenantMdataList.getFieldCaption());
                            }
                            if("[]".equals(value)){
                                value="";
                            }
                            // String
                            if (dId.equals(dId2)&&detectionObject.getIsPass().equals("0")) {
                                if (value.length() > Integer.parseInt(item.getValue())) {
                                    //插入错误日志
                                    detailLogsService.insertNewDetailLogs(id,"组卷字段"+tenantMdataList.getFieldCaption() + "元数据项数据长度超出设置项",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);
                                }
                            } else if (dId.equals(dId3)&&detectionObject.getIsPass().equals("0")) {
                                boolean flag = true;
                                if (item.getValue().equals("0")) {
                                    //字符不再验证
                                } else if (item.getValue().equals("1")) {
                                    //数字类型
                                    flag = detectionUtil.verifyNumber(value);
                                } else if (item.getValue().equals("2")) {
                                    flag = detectionUtil.checkDataType(value);
                                }
                                if (!flag) {
                                    //插入错误日志
                                    detailLogsService.insertNewDetailLogs(id,"组卷字段" + tenantMdataList.getFieldCaption() + "元数据项数据类型、格式检测不符合设置项",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);
                                }
                            } else if (dId.equals(dId4)&&detectionObject.getIsPass().equals("0")) {
                                //检测项目：设定值域的元数据项值域符合度检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if (value.indexOf(a) >= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id,"组卷字段" + tenantMdataList.getFieldCaption() + "的值不在值域范围内",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);
                                }
                            } else if (dId.equals(dId5)&&detectionObject.getIsPass().equals("0")) {
                                //元数据项数据值合理性检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if (value.indexOf(a) >= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id,"组卷字段" + tenantMdataList.getFieldCaption() + "的值不合理",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);
                                }
                            } else if (dId.equals(dId6)&&detectionObject.getIsPass().equals("0")) {
                                //元数据项数据包含特殊字符检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if (value.indexOf(a) <= 0) {
                                        flag = true;
                                    }

                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id,"组卷字段" + tenantMdataList.getFieldCaption() + "的值中含有不支持的特殊字符",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);
                                }
                            } else if (dId.equals(dId7)&&detectionObject.getIsPass().equals("0")) {
                                //档号规范性检测
                                String rq ="";
                                if(n.has(juanrq)){
                                    rq= n.getString(juanrq);
                                }
                           /*     if (rq == null || "".equals(rq)) {
                                    detailLogsService.insertNewDetailLogs(id,"组卷字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);
                                }else {*/
                                if(!j.has("档号")){
                                    detailLogsService.insertNewDetailLogs(id,"组卷字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);

                                }else {
                                    if(j.get("档号") instanceof JSONObject) {

                                        net.sf.json.JSONObject jsonObject = j.getJSONObject("档号");

                                        List<String> message = detectionUtil.checkDh(categoryId, type, rq, jsonObject, tenantMdataList.getFieldCaption(),j.getString("电子档案号"),null);
                                        //验证档号规则
                                        for (String str : message) {
                                            detailLogsService.insertNewDetailLogs(id, str, DateUtils.getNowDate(), j.getString("电子档案号"), "", "1", dId);
                                        }
                                    }else{
                                        detailLogsService.insertNewDetailLogs(id,"组卷字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合,未找到档号规则！",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);

                                    }
                                }
                                /*}*/
                            } else if (dId.equals(dId8)&&detectionObject.getIsPass().equals("0")) {
                                //元数据项数据重复性检测
                                //验证数据库里是否有已有这些值
                                int count = detectionUtil.checkRepeatability(subTableName, tenantMdataList.getFieldName(),value);
                                if("1".equals(lx)) {
                                    if (count >=1) {
                                        detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), j.getString("电子档案号"), "", "1", dId);
                                    }
                                }else{
                                    if (count > 1) {
                                        detailLogsService.insertNewDetailLogs(id, "组卷字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), j.getString("电子档案号"), "", "1", dId);
                                    }
                                }
                            }else if (dId.equals(dId19)&&detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "元数据项完整性检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);

                                }
                            }else if (dId.equals(dId20)&&detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);

                                }else if(n.getString(tenantMdataList.getFieldCaption())==null||"".equals(n.getString(tenantMdataList.getFieldCaption()))){
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,组卷字段"+tenantMdataList.getFieldCaption()+"字段值为空！",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);
                                }
                            }else if(dId.equals(dId26)&&detectionObject.getIsPass().equals("0")){
                                //检测项目：信息包元数据完整性检测
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "信息包元数据完整性检测不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);

                                }
                            }else if(dId.equals(dId28)&&detectionObject.getIsPass().equals("0")) {
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "信息包中元数据的可读性不符合！组卷字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),j.getString("电子档案号"),"","1",dId);

                                }
                            }
                            break;
                        }
                    }
                }

                if (dId.equals(dId22)&&detectionObject.getIsPass().equals("0")) {
                    // 连续性元数据项检测
                    if(type.equals(1)) {
                        if (!n.has(juanAjh)) {
                            detailLogsService.insertNewDetailLogs(id, path + "路径下的"+juanAjh+"为空", DateUtils.getNowDate(), j.getString("电子档案号"), "", "1", dId);

                        } else {
                            if(!StringUtils.isEmpty(n.getString(juanAjh))&&!"[]".equals(n.getString(juanAjh))) {
                                List list = (List) params.get("list");
                                list.add(Integer.parseInt(n.getString(juanAjh)));
                                params.put("list", list);

                                List dhList = (List) params.get("dhList");
                                dhList.add(j.getString("电子档案号"));
                                params.put("dhList", dhList);
                            }else {
                                detailLogsService.insertNewDetailLogs(id, path + "路径下的"+juanAjh+"为空", DateUtils.getNowDate(), j.getString("电子档案号"), "", "1", dId);

                            }
                        }
                        if (p == (num - 1)) {
                            List<DetailLogs>detailLogsList  = detectionUtil.checkISContinuous( (List) params.get("list"),new ArrayList(),(List) params.get("dhList"),new ArrayList(),id,dId,"1");
                            if (detailLogsList.size()>0) {
                                detailLogsMapper.inserDetailLogsList(detailLogsList,new DetailLogs().getTableName());                            }
                        }
                    }
                }
            }
            //此处需要解析卷内件
            List jianList=new ArrayList();
            List dhList=new ArrayList();
            List parentDhList=new ArrayList();

            if(jian instanceof JSONArray){
                TenantMdataList mdataList2 = new TenantMdataList();
                mdataList2.setIsMetadata(1);
                mdataList2.setCategoryId(categoryId);
                mdataList2.setType(0);
                List<TenantMdataList> tenantMdataLists2 = detectionSchemeService.getSchemelist(mdataList2);
                for(int i=0;i<((JSONArray) jian).size();i++) {
                    count1++;

                    JSONObject jsonObject = ((JSONArray) jian).getJSONObject(i);
                    //获取日期
                    //获取日期
                    String newRq ="";
                    if(jsonObject.has(jianrq)) {
                        newRq = jsonObject.getString(jianrq);
                    }
                    newRq = "[]".equals(newRq) ? "" : newRq;
                    //获取文件的完整性
                    List<Map> list1 = detectionObjectMapper.getDh(newRq, SecurityUtils.getLoginUser().getSysUser().getTenantCode().toUpperCase(), categoryId);
                    TenantCodeRule yqdaCoderuleModel = new TenantCodeRule();
                    String dh1 = "";
                    String lj=detectionUtil.getDhLj("v",newRq,categoryId);

                    if (list1.size() > 0) {
                        yqdaCoderuleModel = tenantCodeRuleMapper.selectYqdaCoderuleModelById(Long.parseLong(list1.get(0).get("RULEID").toString()), yqdaCoderuleModel.getTableName());
                        TenantMdataList mdataList1 = new TenantMdataList();
                        mdataList1.setCategoryId(categoryId);
                        mdataList1.setFieldName(yqdaCoderuleModel.getfColumnname().toString());
                        List<TenantMdataList> tenantMdataLists1 = detectionSchemeService.getSchemelist(mdataList1);
                        String name = tenantMdataLists1.get(0).getFieldCaption();
                        //获取件的档号的组成字段
                        if(jsonObject.has(name)) {
                            dh1 = jsonObject.getString(name);
                        }else{
                            String bl=lj.split(";&")[1];
                            String zh=jsonObject.getString(j.getJSONObject("档号").getString("件档号组成字段"));
                            String val="";
                            for(int m=0;m<Integer.parseInt(bl)-zh.length();m++){
                                val+="0";
                            }
                            dh1 =j.getString("电子档案号")+lj.split(";&")[0]+val+jsonObject.getString(j.getJSONObject("档号").getString("件档号组成字段"));

                        }
                    }else{
                        String bl=lj.split(";&")[1];
                        String zh=jsonObject.getString(j.getJSONObject("档号").getString("件档号组成字段"));
                        String val="";
                        for(int m=0;m<Integer.parseInt(bl)-zh.length();m++){
                            val+="0";
                        }
                        dh1 =j.getString("电子档案号")+lj.split(";&")[0]+val+jsonObject.getString(j.getJSONObject("档号").getString("件档号组成字段"));
                    }

                    for (DetectionObject detectionObject : detectionObjects) {
                        Long dId = detectionObject.getdId();
                        DetectionItem jianDetectionItem = new DetectionItem();
                        jianDetectionItem.setObjId(detectionObject.getId());
                        jianDetectionItem.setType("0");
                        List<DetectionItem> jianDetectionItems = detectionItemMapper.selectDetectionItemList(jianDetectionItem);
                        //判断卷内件的数据
                        for (DetectionItem item : jianDetectionItems) {
                            //获取名称然后去验证
                            //验证多层件层还是一层
                            for (TenantMdataList tenantMdataList : tenantMdataLists2) {
                                if (tenantMdataList.getId().toString().equals(item.getName())) {
                                    String value="";
                                    if( jsonObject.has(tenantMdataList.getFieldCaption())) {
                                        value = jsonObject.getString(tenantMdataList.getFieldCaption());
                                    }
                                    if("[]".equals(value)){
                                        value="";
                                    }
                                    if (dId.equals(dId2) && detectionObject.getIsPass().equals("0")) {
                                        if (value.length() > Integer.parseInt(item.getValue())) {
                                            //插入错误日志
                                            detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "元数据项数据长度超出设置项", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                        }
                                    } else if (dId.equals(dId3) && detectionObject.getIsPass().equals("0")) {
                                        boolean flag = true;
                                        if (item.getValue().equals("0")) {
                                            //字符不再验证
                                        } else if (item.getValue().equals("1")) {
                                            //数字类型
                                            flag = detectionUtil.verifyNumber(value);
                                        } else if (item.getValue().equals("2")) {
                                            flag = detectionUtil.checkDataType(value);
                                        }
                                        if (!flag) {
                                            //插入错误日志
                                            detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "元数据项数据类型、格式检测不符合设置项", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                        }
                                    } else if (dId.equals(dId4) && detectionObject.getIsPass().equals("0")) {
                                        //检测项目：设定值域的元数据项值域符合度检测
                                        boolean flag = false;
                                        String[] arr = item.getValue().split(",");
                                        for (String a : arr) {
                                            if (value.indexOf(a) >= 0) {
                                                flag = true;
                                            }

                                        }
                                        if (!flag) {
                                            detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的值不在值域范围内", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                        }
                                    } else if (dId.equals(dId5) && detectionObject.getIsPass().equals("0")) {
                                        //元数据项数据值合理性检测
                                        boolean flag = false;
                                        String[] arr = item.getValue().split(",");
                                        for (String a : arr) {
                                            if (value.indexOf(a) >= 0) {
                                                flag = true;
                                            }

                                        }
                                        if (!flag) {
                                            detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的值不合理", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                        }
                                    } else if (dId.equals(dId6) && detectionObject.getIsPass().equals("0")) {
                                        //元数据项数据包含特殊字符检测
                                        boolean flag = false;
                                        String[] arr = item.getValue().split(",");
                                        for (String a : arr) {
                                            if (value.indexOf(a) <= 0) {
                                                flag = true;
                                            }

                                        }
                                        if (!flag) {
                                            detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的值中含有不支持的特殊字符", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                        }
                                    } else if (dId.equals(dId7) && detectionObject.getIsPass().equals("0")) {
                                        //档号规范性检测
                                        String rq ="";
                                        if(jsonObject.has(jianrq)){
                                            rq = jsonObject.getString(jianrq);
                                        }


                                    /*  if (rq == null || "".equals(rq)) {
                                          detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                      } else*/ if (yqdaCoderuleModel == null || yqdaCoderuleModel.getfColumnname() == null) {
                                            detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                        } else {
                                            if (!j.has("档号")) {
                                                detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                            } else {
                                                if(j.get("档号") instanceof JSONObject) {
                                                    net.sf.json.JSONObject jsonObject1 = j.getJSONObject("档号");

                                                    List<String> message = detectionUtil.checkDh(categoryId, 2, rq, jsonObject1, tenantMdataList.getFieldCaption(),dh1,jsonObject);
                                                    //验证档号规则
                                                    for (String str : message) {
                                                        detailLogsService.insertNewDetailLogs(id, str, DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                                    }
                                                }else{
                                                    detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合,未找到档号规则！", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                                }
                                            }
                                        }
                                    } else if (dId.equals(dId8) && detectionObject.getIsPass().equals("0")) {
                                        //元数据项数据重复性检测
                                        //验证数据库里是否有已有这些值
                                        int count = detectionUtil.checkRepeatability(fileTableName, tenantMdataList.getFieldName(),value);
                                        if (count > 1) {
                                            detailLogsService.insertNewDetailLogs(id, "卷内件字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                        }
                                    } else if (dId.equals(dId19) && detectionObject.getIsPass().equals("0")) {
                                        // 元数据项完整性检测
                                        if (!jsonObject.has(tenantMdataList.getFieldCaption())) {
                                            detailLogsService.insertNewDetailLogs(id, "元数据项完整性检测不符合要求,卷内件字段" + tenantMdataList.getFieldCaption() + "字段不存在！", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                        }
                                    } else if (dId.equals(dId20) && detectionObject.getIsPass().equals("0")) {
                                        // 元数据项完整性检测
                                        if (!jsonObject.has(tenantMdataList.getFieldCaption())) {
                                            detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,卷内件字段" + tenantMdataList.getFieldCaption() + "字段不存在！", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                        } else if (jsonObject.getString(tenantMdataList.getFieldCaption()) == null || "".equals(jsonObject.getString(tenantMdataList.getFieldCaption()))) {
                                            detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,卷内件字段" + tenantMdataList.getFieldCaption() + "字段值为空！", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                        }
                                    } else if (dId.equals(dId26) && detectionObject.getIsPass().equals("0")) {
                                        //检测项目：信息包元数据完整性检测
                                        if (!jsonObject.has(tenantMdataList.getFieldCaption())) {
                                            detailLogsService.insertNewDetailLogs(id, "信息包元数据完整性检测不符合！卷内件字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                        }
                                    } else if (dId.equals(dId28) && detectionObject.getIsPass().equals("0")) {
                                        if (!jsonObject.has(tenantMdataList.getFieldCaption())) {
                                            detailLogsService.insertNewDetailLogs(id, "信息包中元数据的可读性不符合！卷内件字段" + tenantMdataList.getFieldCaption() + "不存在", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                        }
                                    }
                                    break;
                                }
                            }


                        }
                        if(dId.equals(dId30)&&detectionObject.getIsPass().equals("0")){
                            //内容数据格式检测
                            //内容数据格式检测
                            DetectionItem detectionItem1 = new DetectionItem();
                            detectionItem1.setObjId(detectionObject.getId());
                            List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                            List list=detectionUtil.verifyFormat(detectionItems1,path);
                            for(Object str:list){
                                detailLogsService.insertNewDetailLogs(id, "内容数据格式检测不包含"+str.toString(),DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                            }

                        }  else if(dId.equals(dId32)&&detectionObject.getIsPass().equals("0")){
                            DetectionItem detectionItem1 = new DetectionItem();
                            detectionItem1.setObjId(detectionObject.getId());
                            List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                            List list=detectionUtil.verifyFormat(detectionItems1,path);
                            for(Object str:list){
                                detailLogsService.insertNewDetailLogs(id, "内容数据格式长期可用性检测不包含"+str.toString(),DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                            }

                        }else if (dId.equals(dId22) && detectionObject.getIsPass().equals("0")) {
                            // 连续性元数据项检测
                            if (!jsonObject.has(jianJh)) {
                                detailLogsService.insertNewDetailLogs(id, path + "路径下的"+jianJh+"为空", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                            } else {
                                if(!StringUtils.isEmpty(jsonObject.getString(jianJh))&&!"[]".equals(jsonObject.getString(jianJh))) {
                                    jianList.add(Integer.parseInt(jsonObject.getString(jianJh)));
                                    dhList.add(dh1);
                                    parentDhList.add( j.getString("电子档案号"));
                                    //档号
                                    //parentDh
                                }else{
                                    detailLogsService.insertNewDetailLogs(id, path + "路径下的"+jianJh+"为空", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                }

                            }
                            if (i == (((JSONArray) jian).size()-1)) {
                                List<DetailLogs> detailLogsList= detectionUtil.checkISContinuous(new ArrayList(), jianList,dhList,parentDhList,id,dId,"0");
                                if (detailLogsList.size()>0) {
                                    detailLogsMapper.inserDetailLogsList(detailLogsList,new DetailLogs().getTableName());
                                }
                            }
                        }

                    }

                    //附件
                    //校验文件名字
                    if (jsonObject.has("文件数据集")) {
                        Object jsonObject2 = jsonObject.get("文件数据集");
                        if (jsonObject2 instanceof JSONArray) {
                            //多个附件
                            JSONArray jsonArray = (JSONArray) jsonObject2;
                            for (int y=0;y< jsonArray.size();y++) {

                                JSONArray jo = (JSONArray) jsonArray.get(y);
                                JSONObject jo1=(JSONObject)jo.get(0);
                                JSONObject jo2=jo1.getJSONArray("文档数据").getJSONObject(0).getJSONObject("电子属性");
                                String path1 ="";
                                if(jo2.has(pathName)){
                                    path1 =jo2.getString(pathName);
                                }
                                long size=0L;
                                if(jo2.has(fileSizeName)){
                                    size = Long.parseLong(jo2.getString(fileSizeName));
                                }
                                String jw ="";
                                if(jo2.has(hzName)){
                                    jw = jo2.getString(hzName);
                                }
                                String mntPath ="";
                                if(jo2.has(mntPathName)){
                                    mntPath = jo2.getString(mntPathName);
                                }
                                //  String mntPath = sysConfigService.selectConfigByKey("YQ_MNT");
                                String scjs ="";
                                if(jo2.has(scjsName)){
                                    scjs = jo2.getString(scjsName);
                                }
                                String zsmc="";
                                if(jo2.has(realDocName)){
                                    zsmc=jo2.getString(realDocName);
                                }

                                if (StringUtils.isEmpty(zsmc)) {
                                    throw new ServiceException("未配置"+realDocName+"为元数据！");
                                }

                                String md5="";
                                if(jo2.has(md5Hash)){
                                    md5=jo2.getString(md5Hash);
                                }
                                String sm3="";
                                if(jo2.has(sm3Hash)){
                                    sm3=jo2.getString(sm3Hash);
                                }
                                if (StringUtils.isEmpty(mntPath)) {
                                    throw new ServiceException("未配置"+mntPathName+"为元数据！");
                                }
                                File file=null;
                                String fileName="";
                                if(!StringUtils.isEmpty(path1)) {
                                    path1 = mntPath + path1;
                                    file = new File(path1);
                                    fileName=file.getName();
                                }
                                File file3=new File(path);
                                String path3=file3.getParent()+File.separator+dh1+File.separator+zsmc;
                                File file4=new File(path3);
                                for (DetectionObject detectionObject : detectionObjects) {
                                    Long dId = detectionObject.getdId();
                                    DetectionItem jianDetectionItem = new DetectionItem();
                                    jianDetectionItem.setObjId(detectionObject.getId());
/*
                                  jianDetectionItem.setType("0");
*/
                                    List<DetectionItem> jianDetectionItems = detectionItemMapper.selectDetectionItemList(jianDetectionItem);
                                    //判断卷内件的数据
                                    for (DetectionItem item : jianDetectionItems) {
                                        boolean flag = true;
                                        boolean newFlag = true;
                                        if(dId.equals(dId1)&&detectionObject.getIsPass().equals("0")) {
                                            //验证固化项
                                            if (item.getName().equals("1")) {
                                                //计算机不校验 1sm3 5 md5
                                                if(file4.exists()){
                                                    String val = EncryptionUtil.getSM3Hash(path3);
                                                    if(!val.equals(sm3)){
                                                        detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"SM3 HASH值不一致", DateUtils.getNowDate(),  dh1,j.getString("电子档案号"),  "0", dId);
                                                    }
                                                }else {
                                                    detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"文件不存在", DateUtils.getNowDate(),  dh1,j.getString("电子档案号"), "0", dId);

                                                }


                                            } else if (item.getName().equals("5")) {
                                                //计算机不校验 1sm3 5 md5
                                                if(file4.exists()){
                                                    String val = EncryptionUtil.getMD5Hash(path3);
                                                    if(!val.equals(md5)){
                                                        detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"MD5 HASH值不一致", DateUtils.getNowDate(), dh1,j.getString("电子档案号"), "0", dId);
                                                    }
                                                }else {
                                                    detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"文件不存在", DateUtils.getNowDate(), dh1,j.getString("电子档案号"),  "0", dId);

                                                }
                                            }



                                        }
                                        else if (dId.equals(dId10) && detectionObject.getIsPass().equals("0")) {

                                            if (item.getName().equals("1")) {
                                                //计算机不校验
                                            } else if (item.getName().equals("2")) {
                                                //验证名称
                                                if (file4==null||!file4.exists()) {
                                                    flag = false;
                                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"名称不规范", DateUtils.getNowDate(), dh1,j.getString("电子档案号"),  "0", dId);

                                                }
                                            } else if (item.getName().equals("3")) {
                                                if (file4==null||!file4.exists()) {
                                                    flag = false;
                                                } else {
                                                    if (file4.length() != size) {
                                                        flag = false;
                                                    }
                                                }
                                                if (!flag) {
                                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"大小不规范", DateUtils.getNowDate(), dh1,j.getString("电子档案号"), "0", dId);
                                                }
                                            } else if (item.getName().equals("4")) {
                                                if (file4==null||!file4.getName().substring(file4.getName().lastIndexOf(".") + 1).toUpperCase().equals(jw)) {
                                                    flag = false;
                                                }
                                                if (!flag) {
                                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"格式不规范", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                                }
                                            } else if (item.getName().equals("5")) {
                                                if (file4==null||!file4.exists()){
                                                    flag = false;

                                                }else {
                                                    // 获取文件创建时间
                                                    Path path2 = Paths.get(path1);
                                                    // 获取文件属性
                                                    BasicFileAttributes attributes = Files.readAttributes(path2, BasicFileAttributes.class);
                                                    // 获取文件创建时间
                                                    FileTime createTime = attributes.creationTime();
                                                    // 将文件创建时间转换为标准格式
                                                    String dateFormat = sdf.format(createTime.toMillis());

                                                    if (!dateFormat.equals(scjs)) {
                                                        flag = false;
                                                    }

                                                }
                                                if (!flag) {
                                                    detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"上传时间不规范", DateUtils.getNowDate(),dh1,  j.getString("电子档案号"), "0", dId);
                                                }
                                            }
                                         /* if (y==(jsonArray.size()-1)&&!flag) {
                                              detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "1", dId);
                                          }*/
                                        } else if (dId.equals(dId11) && detectionObject.getIsPass().equals("0")) {
                                            if (file4==null||!file4.exists()) {
                                                newFlag = false;
                                            }

                                            if (y == (jsonArray.size()-1) && !newFlag) {
                                                detailLogsService.insertNewDetailLogs(id, "元数据未关联内容数据检测", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);
                                            }
                                        }

                                        if (dId.equals(dId27) && detectionObject.getIsPass().equals("0")) {
                                            if (y == (jsonArray.size()-1)) {
                                                File file1 = new File(path.substring(0, path.lastIndexOf(File.separator) + 1) + jsonObject.getString(dhzd));
                                                if (!file1.exists()) {
                                                    detailLogsService.insertNewDetailLogs(id, "信息包内容数据完整性检测不符合", DateUtils.getNowDate(), dh1,j.getString("电子档案号"),  "0", dId);

                                                } else {
                                                    if (file1.listFiles().length-1 != y) {
                                                        detailLogsService.insertNewDetailLogs(id, "信息包内容数据完整性检测不符合", DateUtils.getNowDate(),dh1,  j.getString("电子档案号"), "0", dId);

                                                    }

                                                }
                                            }
                                        }

                                    }

                                    if (dId.equals(dId39) && detectionObject.getIsPass().equals("0")) {
                                        File file1 = new File(path.substring(0, path.lastIndexOf(File.separator)+1)+dh1 );
                                        if(!StringUtils.isEmpty(path1)){
                                            File file2 = new File(path.substring(0, path.lastIndexOf(File.separator)+1)+ dh1+ path1.substring(path1.lastIndexOf(File.separator)));

                                            if (!file2.exists()) {
                                                detailLogsService.insertNewDetailLogs(id, "载体中多余文件检测文件数目不一致,载体中多余文件检测文件不包含" + path1.substring(path1.lastIndexOf(File.separator)+1), DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                            }
                                        }
                                    }else if(dId.equals(dId35)&&detectionObject.getIsPass().equals("0")){
                                        String path4=path.substring(0, path.lastIndexOf(File.separator)) + path1.substring(path1.lastIndexOf(File.separator));
                                        boolean flag=detectionUtil.IsEncryption(path4,file4.getName().substring(file4.getName().lastIndexOf(".") + 1));
                                        if(flag){
                                            detailLogsService.insertNewDetailLogs(id, "信息包中包含的内容数据格式合规性检测不通过" + zsmc+"加密！", DateUtils.getNowDate(), dh1, j.getString("电子档案号"), "0", dId);

                                        }


                                    }


                                }
                            }
                        }
                    }
                }}
        } catch(Exception e){
            e.printStackTrace();
            throw new ServiceException("四性检测失败"+e.getMessage());

        }
        params.put("dh",dh);
        params.put("count",count1);
        return params;


    }

    public Map analysisXml(Integer type, List<DetectionObject> detectionObjects,Long categoryId,String path,Map params,Long id,String subTableName,int p,int num,String lx) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       // analysis(detectionObjects,type);
        String dh=params.get("dh").toString();
        int count1=Integer.parseInt(params.get("count").toString());
        try {
            InputStreamReader o = new InputStreamReader(new FileInputStream(path));
            String xml = org.apache.commons.io.IOUtils.toString(o);
            net.sf.json.xml.XMLSerializer xmlSerializer = new net.sf.json.xml.XMLSerializer();
            net.sf.json.JSONObject json = (net.sf.json.JSONObject) xmlSerializer.read(xml);
            o.close();
            com.alibaba.fastjson2.JSONObject archiveData = XMLtoJsonUtils.startXMLToJSON(new File(path));
            String archiveType = archiveData.getJSONObject("被签名对象").getJSONObject("封装内容").getJSONObject("档案实体块").getString("聚合层次");
            Integer type1 = null;
            Boolean xmBl =  archiveData.getJSONObject("被签名对象").getJSONObject("封装内容").getJSONObject("档案实体块").getJSONObject("内容描述").containsKey("项目层");
            if(xmBl){
                type1 = 3;
            }else if("组卷".equals(archiveType)){
                type1 = 1;
            }else if("文件".equals(archiveType)){
                type1 = 0;
            }
            if(type1!=type){
                throw new ServiceException("门类类型不匹配！！！");
            }

            TenantMdataList mdataList = new TenantMdataList();
            mdataList.setIsMetadata(1);
            mdataList.setCategoryId(categoryId);
            mdataList.setType(0);
            List<TenantMdataList> tenantMdataLists = detectionSchemeService.getSchemelist(mdataList);
            String pathName="";
            String fileSizeName="";
            String hzName="";
            String mntPathName="";
            String scjsName="";
            String realDocName="";
            String md5Hash="";
            String sm3Hash="";
            String jianrq="";
            String jianjh="";
            TenantCategory tenantCategory=tenantCategoryMapper.selectTenantCategoryByID(categoryId,new TenantCategory().getTableName());
            List<Map<String,Object>> maps=detectionObjectMapper.getName(tenantCategory.getGroupId(),2," FIELD_NAME='PATH' OR FIELD_NAME='DOC_FILE_SIZE' OR FIELD_NAME='DOC_FILE_TYPE' OR FIELD_NAME='DOC_MNT' OR FIELD_NAME='ACTION_TIME' OR  FIELD_NAME='REAL_DOC_NAME' OR  FIELD_NAME='FILE_ONLY_VAL_GM' OR  FIELD_NAME='FILE_ONLY_VAL' ",new TenantMdataList().getTableName());
            List<Map<String,Object>> jianMaps=detectionObjectMapper.getName(tenantCategory.getGroupId(),0," FIELD_NAME='RQ' OR  FIELD_NAME='JH'  ",new TenantMdataList().getTableName());

            for(Map map:maps){
                if(map.get("FIELD_NAME").equals("PATH")){
                    pathName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("DOC_FILE_SIZE")){
                    fileSizeName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("DOC_FILE_TYPE")){
                    hzName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("DOC_MNT")){
                    mntPathName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("ACTION_TIME")){
                    scjsName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("REAL_DOC_NAME")){
                    realDocName=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("FILE_ONLY_VAL")){
                    md5Hash=map.get("FIELD_CAPTION").toString();
                }else if(map.get("FIELD_NAME").equals("FILE_ONLY_VAL_GM")){
                    sm3Hash=map.get("FIELD_CAPTION").toString();
                }


            }
            for(Map map:jianMaps){
                if(map.get("FIELD_NAME").equals("RQ")){
                    jianrq=map.get("FIELD_CAPTION").toString();
                }else  if(map.get("FIELD_NAME").equals("JH")){
                    jianjh=map.get("FIELD_CAPTION").toString();
                }
            }
            //各项检测先解析xml
            //组件
            net.sf.json.JSONObject j=null;
            net.sf.json.JSONObject j1 = json.getJSONObject("被签名对象");
            Object j2=j1.get("封装内容");

            //判断封装内容是JSONOBJECT还是JSONARRY
            if(j2 instanceof JSONArray){
                j=((net.sf.json.JSONArray) j2).getJSONObject(0);
                //.getJSONObject("档案实体块");
            }else if(j2 instanceof JSONObject){
                j=((JSONObject) j2).getJSONObject("档案实体块");
            }


            dh += j.getString("电子档案号")+",";

            //获取内容描述
            net.sf.json.JSONObject n = j.getJSONObject("内容描述");
            //开始验证各项
            for (DetectionObject detectionObject : detectionObjects) {
                Long dId = detectionObject.getdId();
                DetectionItem detectionItem = new DetectionItem();
                detectionItem.setObjId(detectionObject.getId());
                detectionItem.setType("0");
                List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
                for (DetectionItem item : detectionItems) {
                    //获取名称然后去验证
                    for (TenantMdataList tenantMdataList : tenantMdataLists) {
                        if (tenantMdataList.getId().toString().equals(item.getName())) {
                            String value="";
                            if(n.has(tenantMdataList.getFieldCaption())){
                                value = n.getString(tenantMdataList.getFieldCaption());
                            }
                            if("[]".equals(value)){
                                value="";
                            }
                            if (dId.equals(dId2)&&detectionObject.getIsPass().equals("0")) {
                                if (value.length() > Integer.parseInt(item.getValue())) {
                                    //插入错误日志
                                    detailLogsService.insertNewDetailLogs(id,"字段"+tenantMdataList.getFieldCaption() + "元数据项数据长度超出设置项",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                                }
                            } else if (dId.equals(dId3)&&detectionObject.getIsPass().equals("0")) {
                                boolean flag = true;
                                if (item.getValue().equals("0")) {
                                    //字符不再验证
                                } else if (item.getValue().equals("1")) {
                                    //数字类型
                                    flag = detectionUtil.verifyNumber(value);
                                } else if (item.getValue().equals("2")) {
                                    flag = detectionUtil.checkDataType(value);
                                }
                                if (!flag) {
                                    //插入错误日志
                                    detailLogsService.insertNewDetailLogs(id,"字段" + tenantMdataList.getFieldCaption() + "元数据项数据类型、格式检测不符合设置项",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                                }
                            } else if (dId.equals(dId4)&&detectionObject.getIsPass().equals("0")) {
                                //检测项目：设定值域的元数据项值域符合度检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if (value.indexOf(a) >= 0) {
                                        flag = true;
                                    }
                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id,"字段" + tenantMdataList.getFieldCaption() + "的值不在值域范围内",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                                }
                            } else if (dId.equals(dId5)&&detectionObject.getIsPass().equals("0")) {
                                //元数据项数据值合理性检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if (value.indexOf(a) >= 0) {
                                        flag = true;
                                    }
                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id,"字段" + tenantMdataList.getFieldCaption() + "的值不合理",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                                }
                            } else if (dId.equals(dId6)&&detectionObject.getIsPass().equals("0")) {
                                //元数据项数据包含特殊字符检测
                                boolean flag = false;
                                String[] arr = item.getValue().split(",");
                                for (String a : arr) {
                                    if (value.indexOf(a) <= 0) {
                                        flag = true;
                                    }
                                }
                                if (!flag) {
                                    detailLogsService.insertNewDetailLogs(id,"字段" + tenantMdataList.getFieldCaption() + "的值中含有不支持的特殊字符",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                                }
                            } else if (dId.equals(dId7)&&detectionObject.getIsPass().equals("0")) {
                                //档号规范性检测
                                String rq = "";
                                if(n.has(jianrq)){
                                    rq= n.getString(jianrq);
                                }


                                /*    if (rq == null || "".equals(rq)) {
                                        detailLogsService.insertNewDetailLogs(id,"字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                                    }else {*/
                                if(!j.has("档号")){
                                    detailLogsService.insertNewDetailLogs(id,"字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                                }else {
                                    if(j.get("档号") instanceof JSONObject) {
                                        net.sf.json.JSONObject jsonObject = j.getJSONObject("档号");

                                        List<String> message = detectionUtil.checkDh(categoryId, type, rq, jsonObject, tenantMdataList.getFieldCaption(),j.getString("电子档案号"),null);
                                        //验证档号规则
                                        for (String str : message) {
                                            detailLogsService.insertNewDetailLogs(id, str, DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                        }
                                    }else{
                                        detailLogsService.insertNewDetailLogs(id,"字段" + tenantMdataList.getFieldCaption() + "的档号规范性不符合,未找到档号规则！",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                                    }
                                }
                                /*}*/
                            } else if (dId.equals(dId8)&&detectionObject.getIsPass().equals("0")) {
                                //元数据项数据重复性检测
                                //验证数据库里是否有已有这些值
                                int count = detectionUtil.checkRepeatability(subTableName, tenantMdataList.getFieldName(),value);
                                if("1".equals(lx)) {
                                    if (count >= 1) {
                                        detailLogsService.insertNewDetailLogs(id, "字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                    }
                                }else{
                                    if (count > 1) {
                                        detailLogsService.insertNewDetailLogs(id, "字段" + tenantMdataList.getFieldCaption() + "的元数据项数据重复性检测不符合", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                    }
                                }
                            }else if (dId.equals(dId19)&&detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "元数据项完整性检测不符合要求,"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                                }
                            }else if (dId.equals(dId20)&&detectionObject.getIsPass().equals("0")) {
                                // 元数据项完整性检测
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,"+tenantMdataList.getFieldCaption()+"字段不存在！",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                                }else if(n.getString(tenantMdataList.getFieldCaption())==null||"".equals(n.getString(tenantMdataList.getFieldCaption()))){
                                    detailLogsService.insertNewDetailLogs(id, "元数据必填著录项目检测不符合要求,"+tenantMdataList.getFieldCaption()+"字段值为空！",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                                }
                            }else if(dId.equals(dId26)&&detectionObject.getIsPass().equals("0")){
                                //检测项目：信息包元数据完整性检测
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "信息包元数据完整性检测不符合！字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                                }
                            }else if(dId.equals(dId28)&&detectionObject.getIsPass().equals("0")) {
                                if(!n.has(tenantMdataList.getFieldCaption())){
                                    detailLogsService.insertNewDetailLogs(id, "信息包中元数据的可读性不符合！字段"+tenantMdataList.getFieldCaption()+"不存在",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                                }
                            }
                            break;
                        }
                    }

                }
                if(dId.equals(dId30)&&detectionObject.getIsPass().equals("0")){
                    //内容数据格式检测
                    DetectionItem detectionItem1 = new DetectionItem();
                    detectionItem1.setObjId(detectionObject.getId());
                    List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                    List list=detectionUtil.verifyFormat(detectionItems1,path);
                    for(Object str:list){
                        detailLogsService.insertNewDetailLogs(id, "内容数据格式检测不包含"+str.toString(),DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                    }

                }  else if(dId.equals(dId32)&&detectionObject.getIsPass().equals("0")){
                    //内容数据格式检测
                    DetectionItem detectionItem1 = new DetectionItem();
                    detectionItem1.setObjId(detectionObject.getId());
                    List<DetectionItem> detectionItems1 = detectionItemMapper.selectDetectionItemList(detectionItem1);

                    List list=detectionUtil.verifyFormat(detectionItems1,path);
                    for(Object str:list){
                        detailLogsService.insertNewDetailLogs(id, "内容数据格式长期可用性检测不包含"+str.toString(),DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);
                    }

                }else if (dId.equals(dId22)&&detectionObject.getIsPass().equals("0")) {
                    // 连续性元数据项检测
                    if(!n.has(jianjh)){

                        detailLogsService.insertNewDetailLogs(id, path+"路径下的"+jianjh+"为空",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                    }else if("".equals(n.getString(jianjh))||"[]".equals(n.getString(jianjh))){
                        detailLogsService.insertNewDetailLogs(id, path+"路径下的"+jianjh+"为空",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                    }else{
                        if(!StringUtils.isEmpty(n.getString(jianjh))) {
                            List list = (List) params.get("list");
                            list.add(Integer.parseInt(n.getString(jianjh)));
                            params.put("list", list);

                            List dhList = (List) params.get("dhList");
                            dhList.add(j.getString("电子档案号"));
                            params.put("dhList", dhList);

                        }else{
                            detailLogsService.insertNewDetailLogs(id, path+"路径下的"+jianjh+"为空",DateUtils.getNowDate(),j.getString("电子档案号"),"","0",dId);

                        }

                    }
                    if(p==(num-1)){
                        List<DetailLogs> detailLogsList =detectionUtil.checkISContinuous(new ArrayList(), (List) params.get("list"), (List) params.get("dhList"),new ArrayList(),id,dId,"0");
                        if(detailLogsList.size()>0){
                            detailLogsMapper.inserDetailLogsList(detailLogsList,new DetailLogs().getTableName());
                        }
                    }
                }
            }
            //附件
            //校验文件名字
            if (n.has("文件数据集")) {
                Object jsonObject = n.get("文件数据集");
                if (jsonObject instanceof JSONArray) {
                    //多个附件
                    JSONArray jsonArray = (JSONArray) jsonObject;
                    for (int i = 0; i < jsonArray.size(); i++) {

                        JSONArray jo = jsonArray.getJSONArray(i);
                        JSONObject jo1=(JSONObject)jo.get(0);
                        JSONObject jo2=jo1.getJSONArray("文档数据").getJSONObject(0).getJSONObject("电子属性");
                        String path1 ="";
                        if(jo2.has(pathName)){
                            path1 =jo2.getString(pathName);
                        }
                        long size=0L;
                        if(jo2.has(fileSizeName)){
                            size = Long.parseLong(jo2.getString(fileSizeName));
                        }
                        String jw ="";
                        if(jo2.has(hzName)){
                            jw = jo2.getString(hzName);
                        }

                        String mntPath ="";
                        if(jo2.has(mntPathName)){
                            mntPath = jo2.getString(mntPathName);
                        }


                        String scjs ="";
                        if(jo2.has(scjsName)){
                            scjs = jo2.getString(scjsName);
                        }
                        String zsmc="";
                        if(jo2.has(realDocName)){
                            zsmc=jo2.getString(realDocName);
                        }
                        String md5="";
                        if(jo2.has(md5Hash)){
                            md5=jo2.getString(md5Hash);
                        }
                        String sm3="";
                        if(jo2.has(sm3Hash)){
                            sm3=jo2.getString(sm3Hash);
                        }
                        if (StringUtils.isEmpty(mntPath)) {
                            throw new ServiceException("未配置"+mntPathName+"为元数据！");
                        }
                        File file=null;
                        String fileName="";
                        if(!StringUtils.isEmpty(path1)) {
                            path1 = mntPath + path1;
                            file = new File(path1);
                            fileName=file.getName();
                        }
                        File file3=new File(path);
                        String path3=file3.getParent()+File.separator+zsmc;
                        File file4=new File(path3);
                        for (DetectionObject detectionObject : detectionObjects) {
                            Long dId = detectionObject.getdId();
                            DetectionItem detectionItem = new DetectionItem();
                            detectionItem.setObjId(detectionObject.getId());
                            /* detectionItem.setType("0");*/
                            List<DetectionItem> detectionItems = detectionItemMapper.selectDetectionItemList(detectionItem);
                            for (DetectionItem item : detectionItems) {
                                boolean flag = true;
                                boolean newFlag = true;
                                if(dId.equals(dId1)&&detectionObject.getIsPass().equals("0")) {
                                    //验证固化项
                                    if (item.getName().equals("1")) {
                                        //计算机不校验 1sm3 5 md5
                                        if(file4.exists()){
                                            String val = EncryptionUtil.getSM3Hash(path3);
                                            if(!val.equals(sm3)){
                                                detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"SM3 HASH值不一致", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                            }
                                        }else {
                                            detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"文件不存在", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);

                                        }


                                    } else if (item.getName().equals("5")) {
                                        //计算机不校验 1sm3 5 md5
                                        if(file4.exists()){
                                            String val = EncryptionUtil.getMD5Hash(path3);
                                            if(!val.equals(md5)){
                                                detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"MD5 HASH值不一致", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                            }
                                        }else {
                                            detailLogsService.insertNewDetailLogs(id, "固化信息有效性检测不通过,"+zsmc+"文件不存在", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);

                                        }
                                    }



                                }
                                else if(dId.equals(dId10)&&detectionObject.getIsPass().equals("0")) {

                                    if (item.getName().equals("1")) {
                                        //计算机不校验
                                    } else if (item.getName().equals("2")) {
                                        //验证名称
                                        if (file4==null||!file4.exists()) {
                                            flag = false;
                                            detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"名称不规范", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);

                                        }
                                    } else if (item.getName().equals("3")) {
                                        if (file4==null||!file4.exists()) {
                                            flag = false;
                                        } else {
                                            if (file4==null||file4.length() != size) {
                                                flag = false;
                                            }
                                        }
                                        if(!flag) {
                                            detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"大小不规范", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                        }
                                    } else if (item.getName().equals("4")) {
                                        if ( file4==null||!file4.getName().substring(file4.getName().lastIndexOf(".") + 1).toUpperCase().equals(jw)) {
                                            flag = false;
                                        }
                                        if(!flag) {
                                            detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"格式不规范", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                        }
                                    } else if (item.getName().equals("5")) {
                                        if (file4 == null||!file4.exists()) {
                                            flag = false;
                                        } else {
                                            // 获取文件创建时间
                                            Path path2 = Paths.get(path1);
                                            // 获取文件属性
                                            BasicFileAttributes attributes = Files.readAttributes(path2, BasicFileAttributes.class);
                                            // 获取文件创建时间
                                            FileTime createTime = attributes.creationTime();
                                            // 将文件创建时间转换为标准格式
                                            String dateFormat = sdf.format(createTime.toMillis());

                                            if (!dateFormat.equals(scjs)) {
                                                flag = false;
                                            }
                                        }
                                        if(!flag) {
                                            detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致,"+zsmc+"上传时间不规范", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                        }
                                    }
                                    /*        if (i==(jsonArray.size()-1)&&!flag) {
                                                detailLogsService.insertNewDetailLogs(id, "内容数据的电子属性不一致", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                            }*/
                                }else if(dId.equals(dId11)&&detectionObject.getIsPass().equals("0")){
                                    if (file4==null||!file4.exists()) {
                                        newFlag = false;
                                    }

                                    if (i==(jsonArray.size()-1)&&!newFlag) {
                                        detailLogsService.insertNewDetailLogs(id, "元数据未关联内容数据检测", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);
                                    }
                                }

                                if(dId.equals(dId27)&&detectionObject.getIsPass().equals("0")){
                                    if(i==(jsonArray.size()-1)){
                                        File file1=new File(path.substring(0,path.lastIndexOf(File.separator)));
                                        if(!file1.exists()){
                                            detailLogsService.insertNewDetailLogs(id, "信息包内容数据完整性检测不符合", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);

                                        }else{
                                            if((file1.listFiles().length-2)!=i){
                                                detailLogsService.insertNewDetailLogs(id, "信息包内容数据完整性检测不符合", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);

                                            }

                                        }
                                    }
                                }
                            }
                            if(dId.equals(dId39)&&detectionObject.getIsPass().equals("0")){
                                File file1=new File(path.substring(0,path.lastIndexOf(File.separator)));

                                if(((jsonArray.size()-1)==i)&&(file1.listFiles().length-1!=jsonArray.size())){
                                    detailLogsService.insertNewDetailLogs(id, "载体中多余文件检测文件数目不一致", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);

                                }

                                if(!StringUtils.isEmpty(path1)){
                                    File file2 = new File(path.substring(0, path.lastIndexOf(File.separator)) + path1.substring(path1.lastIndexOf(File.separator)));

                                    if (!file2.exists()) {
                                        detailLogsService.insertNewDetailLogs(id, "载体中多余文件检测文件不包含" + path1.substring(path1.lastIndexOf(File.separator)), DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);

                                    }
                                }

                            }else if(dId.equals(dId35)&&detectionObject.getIsPass().equals("0")){
                                String path4=path.substring(0, path.lastIndexOf(File.separator)) + path1.substring(path1.lastIndexOf(File.separator));
                                boolean flag=detectionUtil.IsEncryption(path4,file4.getName().substring(file4.getName().lastIndexOf(".") + 1));
                                if(flag){
                                    detailLogsService.insertNewDetailLogs(id, "信息包中包含的内容数据格式合规性检测不通过" + zsmc+"加密！", DateUtils.getNowDate(), j.getString("电子档案号"), "", "0", dId);


                                }


                            }

                        }

                    }
                }
            }

        } catch(Exception e){
            e.printStackTrace();
            throw new ServiceException("四性检测失败:"+e.getMessage());

        }
        count1++;
        params.put("dh",dh);
        params.put("count",count1);
        return params;

    }



    public  List<String> getFiles(String path,List list) {

        File file = new File(path);
        // 如果这个路径是文件夹
        if (file.isDirectory()) {
            // 获取路径下的所有文件
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                // 如果还是文件夹 递归获取里面的文件 文件夹
                if (files[i].isDirectory()) {
                    getFiles(files[i].getPath(),list);
                } else {
                    if(files[i].getName().equals("档案元数据.xml")){
                        list.add(files[i].getPath());
                    }
                }

            }
        } else {
            if(file.getName().equals("档案元数据.xml")){
                list.add(file.getPath());
            }
        }
        return list;
    }

    private String getDictVal(String fieldName,Object dict){

        String DictVal = "";
        List<TenantSysDictData> list = sysDictTypeService.selectDictDataByType(fieldName);
        if(list!=null && list.size()>0){
            if(dict!=null) {
                for (TenantSysDictData dictData : list) {
                    if (dict.equals(dictData.getDictValue())) {
                        DictVal = dictData.getDictLabel();
                        break;
                    }
                }
            }
        }else {
            DictVal = getNull(dict);
        }
        return DictVal;
    }

    private String getNull(Object val){
        if(val == null){
            return "";
        }else {
            return String.valueOf(val);
        }
    }
    public Long [] getLongList(List list){
        Long[] array = new Long[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = Long.parseLong( list.get(i).toString());
        }
        return array;

    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map handoverDetection(DetectionPackage packages) {

        Map map=new HashMap();
        String code=packages.getCode();
        DetectionScheme ds=new DetectionScheme();
        TenantCategory category=new TenantCategory();

        DetectionScheme detectionScheme=detectionSchemeMapper.selectDetectionSchemeByCode(code,ds.getTableName());
        int count=this.getDetailCount(detectionScheme.getId());
        if(count<=0){
            throw new ServiceException("该方案未配置检测项,请先配置检测项！");
        }

        Long categoryId=detectionScheme.getCategoryId();
        String subTableName=detectionScheme.getSubTableName();
        //判断该门类是项目还是组卷还是组件
        TenantCategory tenantCategory= tenantCategoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        Integer type=packages.getDaType();
        //获取配置项
        DetectionObject detectionObject=new DetectionObject();
        detectionObject.setpId(detectionScheme.getId());
        detectionObject.setIsDetection("1");

        List<DetectionObject> detectionObjects=detectionObjectMapper.selectDetectionObjectList(detectionObject);
        //去校验，验证是否成功
        String daIds=packages.getDaIds();
        List<String> daIdArr=Arrays.asList(daIds.split(","));
        List<Long> sxIds=new ArrayList<>();
        //每个一个数据
        Map params = new HashMap();
        params.put("daIdList", new ArrayList<>());
        params.put("itemIdList", new ArrayList<>());
        params.put("folderIdList", new ArrayList<>());
        params.put("allDaIdList", new ArrayList<>());
        params.put("allItemIdList", new ArrayList<>());
        params.put("allFolderIdList", new ArrayList<>());
        for(int i=0;i<daIdArr.size();i++) {
            Long id=SnowflakeIdGenerator.generateId();
            sxIds.add(id);
            params.put("dh", "");
            params.put("dhList", new ArrayList<>());
            params.put("count", "0");
            params.put("list", new ArrayList<>());
            params.put("parentDhList", new ArrayList<>());
            List<DetectionPackage> packages1 = new ArrayList<>();
            TenantItemFolder tenantItemFolder = new TenantItemFolder();
            List<DetectionPackage> detectionPackages = new ArrayList<>();
            if (type.equals(3)) {
                List<Long> folderIds = detectionObjectMapper.getFolderIdsBtItemId(tenantItemFolder.getTableName(), Long.parseLong(daIdArr.get(i)), SecurityUtils.getTenantCode());
                int count1 = 0;
                for (int j = 0; j < folderIds.size(); j++) {
                    Long folderId = folderIds.get(j);
                    DetectionPackage d = new DetectionPackage();
                    d.setDaType(1);
                    d.setDaId(folderId);
                    d.setCategoryId(categoryId);
                    d.setCode(code);
                    d.setLink(packages.getLink());
                    d.setMenuType(packages.getMenuType());
                    params = treatAnalysisVolume(1, detectionObjects, categoryId, d, params, id, tenantCategory.getFolderTableName(), j, folderIds.size(), tenantCategory.getEfileTableName(), tenantCategory.getFileTableName(), daIdArr.get(i));
                }

            } else {

                DetectionPackage d = new DetectionPackage();
                if (type.equals(0)) {
                    d.setDaType(0);
                } else {
                    d.setDaType(1);

                }
                d.setDaId(Long.parseLong(daIdArr.get(i)));
                d.setCategoryId(categoryId);
                d.setCode(code);
                d.setLink(packages.getLink());
                d.setMenuType(packages.getMenuType());
                detectionPackages.add(d);
            }
            packages1.addAll(detectionPackages);
            for (int n = 0; n < packages1.size(); n++) {
                //解析json然后获取内容去校验
                if (type.equals(0)) {
                    params = treatAnalysisDa(type, detectionObjects, categoryId, packages1.get(n), params, id, subTableName, n, packages1.size(), tenantCategory.getEfileTableName(), "", "组件", "1", 0L, "");
                } else if (type.equals(1)) {
                    params = treatAnalysisVolume(type, detectionObjects, categoryId, packages1.get(n), params, id, subTableName, n, packages1.size(), tenantCategory.getEfileTableName(), tenantCategory.getFileTableName(), "");
                }
            }
            insetSxLogs(detectionObjects,id,type,params,categoryId,packages.getLink());
        }

        Map newmap=updateDaState(params,type,tenantCategory,sxIds);
        if(newmap!=null){
            map.putAll(newmap);
        }
        return map;

    }
    // 修改档案四性检测状态
    public Map updateDaState( Map params,Integer type,TenantCategory tenantCategory,List<Long> sxIds){
        Map map=new HashMap();
        List daIdList = (List) params.get("daIdList");
        List itemIdList = (List) params.get("itemIdList");
        List folderIdList = (List) params.get("folderIdList");
        List allDaIdList = (List) params.get("allDaIdList");
        List allItemIdList = (List) params.get("allItemIdList");
        List allFolderIdList = (List) params.get("allFolderIdList");
        if (type.equals(3)) {
            if(allItemIdList.size()>0){
                detectionObjectMapper.updateStateByfoldeId(allItemIdList, tenantCategory.getItemTableName(), "1", "ID");
                detectionObjectMapper.updateStateByfoldeId(allItemIdList, new TenantYqItem().getTableName(), "1", "ITEM_ID");
                //修改
                for(int q=0;q<allItemIdList.size();q++){
                    Long daId=Long.parseLong(allItemIdList.get(q).toString());
                    Long sxId=sxIds.get(q);
                    //判断该档案是否在中间表里
                    int count1=detectionObjectMapper.getSxCount(daId,SecurityUtils.getTenantCode());
                    if(count1>0){
                        detectionObjectMapper.updateSxId(sxId,SecurityUtils.getTenantCode(),daId);
                    } else{
                        detectionObjectMapper.insertSxId(SnowflakeIdGenerator.generateId(),sxId,SecurityUtils.getTenantCode(),daId);

                    }

                }

            }
            if(itemIdList.size()>0){
                detectionObjectMapper.updateStateByfoldeId(itemIdList, tenantCategory.getItemTableName(), "0", "ID");
                detectionObjectMapper.updateStateByfoldeId(itemIdList, new TenantYqItem().getTableName(), "0", "ITEM_ID");

            }
            map.put("daId",itemIdList);


        } else if (type.equals(1)) {
            if (allFolderIdList.size() > 0) {
                detectionObjectMapper.updateStateByfoldeId(allFolderIdList, tenantCategory.getFolderTableName(), "1", "ID");
                detectionObjectMapper.updateStateByfoldeId(allFolderIdList, new TenantYqFolder().getTableName(), "1", "FOLDER_ID");

                for(int q=0;q<allFolderIdList.size();q++){
                    Long daId=Long.parseLong(allFolderIdList.get(q).toString());
                    Long sxId=sxIds.get(q);
                    //判断该档案是否在中间表里
                    int count1=detectionObjectMapper.getSxCount(daId,SecurityUtils.getTenantCode());
                    if(count1>0){
                        detectionObjectMapper.updateSxId(sxId,SecurityUtils.getTenantCode(),daId);
                    } else{
                        detectionObjectMapper.insertSxId(SnowflakeIdGenerator.generateId(),sxId,SecurityUtils.getTenantCode(),daId);

                    }

                }


            }
            if (folderIdList.size() > 0) {
                detectionObjectMapper.updateStateByfoldeId(folderIdList, tenantCategory.getFolderTableName(), "0", "ID");
                detectionObjectMapper.updateStateByfoldeId(folderIdList, new TenantYqFolder().getTableName(), "0", "FOLDER_ID");


            }
            map.put("daId",folderIdList);
        } else if (type.equals(0)) {
            if (allDaIdList.size() > 0) {
                detectionObjectMapper.updateStateByfoldeId(allDaIdList, tenantCategory.getFileTableName(), "1", "ID");
                detectionObjectMapper.updateStateByfoldeId(allDaIdList, new TenantYqda().getTableName(), "1", "DA_ID");

                for(int q=0;q<allDaIdList.size();q++){
                    Long daId=Long.valueOf(allDaIdList.get(q).toString());
                    Long sxId=sxIds.get(q);
                    //判断该档案是否在中间表里
                    int count1=detectionObjectMapper.getSxCount(daId,SecurityUtils.getTenantCode());
                    if(count1>0){
                        detectionObjectMapper.updateSxId(sxId,SecurityUtils.getTenantCode(),daId);
                    } else{
                        detectionObjectMapper.insertSxId(SnowflakeIdGenerator.generateId(),sxId,SecurityUtils.getTenantCode(),daId);

                    }

                }
            }
            if (daIdList.size() > 0) {
                detectionObjectMapper.updateStateByfoldeId(daIdList, tenantCategory.getFileTableName(), "0", "ID");
                detectionObjectMapper.updateStateByfoldeId(daIdList, new TenantYqda().getTableName(), "0", "DA_ID");

            }
            map.put("daId",daIdList);
        }

        return map;

    }

    //新增四性检测记录
    public Map insetSxLogs(List<DetectionObject> detectionObjects,Long id,Integer type,Map params,Long categoryId,String link){
        //查询所有值插入object 以及 总记录表
        int m = 0;
        int znum = 0;
        int failNum = 0;
        String dId = "";
        for (DetectionObject detectionObject1 : detectionObjects) {
            dId += "," + detectionObject1.getdId();
            DetailLogs detailLogs = new DetailLogs();
            detailLogs.setpId(id);
            detailLogs.setdId(detectionObject1.getdId());
            List<DetailLogs> detailLogLists = detailLogsMapper.selectDetailLogsList(detailLogs);
            //判断有多少条档案失败
            Set set = new HashSet();
            for (DetailLogs d : detailLogLists) {
                if (type.equals(0)) {
                    set.add(d.getCheckDh());
                } else if (type.equals(1) || type.equals(3)) {
                    if (StringUtils.isEmpty(d.getCheckParentDh())) {
                        set.add(d.getCheckDh());
                    } else {
                        set.add(d.getCheckParentDh());

                    }

                }
            }
            if (detailLogLists.size() > 0) {
                InspectionLogs inspectionLogs = new InspectionLogs();
                inspectionLogs.setDetectionTime(DateUtils.getNowDate());
                inspectionLogs.setDetectionResult("0");
                inspectionLogs.setdId(detectionObject1.getdId());
                inspectionLogs.setpId(id);
                inspectionLogs.setFailNum(set.size() + "");
                inspectionLogs.setIsPass(detectionObject1.getIsPass());
                inspectionLogsMapper.insertInspectionLogs(inspectionLogs);
                m++;
                failNum++;
            } else {
                InspectionLogs inspectionLogs = new InspectionLogs();
                inspectionLogs.setDetectionTime(DateUtils.getNowDate());
                inspectionLogs.setDetectionResult("1");
                inspectionLogs.setdId(detectionObject1.getdId());
                inspectionLogs.setpId(id);
                inspectionLogs.setFailNum(set.size() + "");
                inspectionLogs.setIsPass(detectionObject1.getIsPass());
                inspectionLogsMapper.insertInspectionLogs(inspectionLogs);
            }
            znum++;
        }
        InspectionRecords inspectionRecords = new InspectionRecords();
        inspectionRecords.setIsDel(0);
        inspectionRecords.setDetectionTime(DateUtils.getNowDate());
        if (m > 0) {
            inspectionRecords.setDetectionResult("0");
        } else {
            inspectionRecords.setDetectionResult("1");
        }
        inspectionRecords.setId(id);
        inspectionRecords.setDetectionLink(link);
        inspectionRecords.setCategoryId(categoryId);
        if (StringUtils.isEmpty(params.get("dh").toString())) {
            inspectionRecords.setDetectionDh("");
        } else {
            inspectionRecords.setDetectionDh(params.get("dh").toString().substring(0, params.get("dh").toString().length() - 1));

        }
        inspectionRecords.setCreateId(SecurityUtils.getUserId());
        inspectionRecordsMapper.insertInspectionRecords(inspectionRecords);
        Map<String,Object>map=new HashMap<>();
        map.put("dId",dId);
        map.put("znum",znum);
        map.put("failNum",failNum);

        return map;
    }


}
